How send Email from server email in laravel 5.3 - php

I am new laravel and i just made a small project of article posting and on user registration i just want to send successfully register email to user email. I searched every where in all tutorials they are giving demo for send mail from gmail and some another email providers. I just want to know is it possible to send the mail simply from server email id ? like cordignator framework:
$this->email->to('rahul#gmail.com')
$this->email->subject('Testing Email')
$this->email->message('hello')
$this->email->send()

set your server mail details in .env file then
run a command php artisan publish
send mail like Mail::to($user)->send(new UserRegister());
and your UserRegister class in app/Mail have one method
public function build()
{
return $this->subject("Welcome to My site")
->view('`vendor.notifications.register`',compact(''));
}
And You can set all message body in resourse/view/vendor/notifications/register
see more on laravel mail

Related

Laravel Mailgun tracking emails

I'm trying to track emails sent via laravel mailgun driver. I want to be able to view the emails in the 'analytics' page of app.mailgun.com.
I am able to send emails using Postman with the following headers: o:tag o:tracking o:tracking-clicks o:tracking-opens and these seem to work fine. I can see these in the 'analytics' page. I have also successfully set up web hooks so I can track individual events for each email.
According to the documentation if I am sending via SMTP I need to send these tags: X-Mailgun-Track: yes, X-Mailgun-Track-Opens = yes. I have set these using the following code in the build method of my mailable class:
$this->withSwiftMessage(function ($message) {
$message->getHeaders()->addTextHeader(
'X-Mailgun-Track', 'yes'
);
$message->getHeaders()->addTextHeader(
'X-Mailgun-Track-Opens', 'yes'
);
});
I can see these headers are added when I open the email in a text editor. The email does not show up in the mailgun 'analytics' page.
Any help on this would be appreciated. Thanks!

My Laravel mail queue gets proccessed but don't send email

please some one should help ive done all required to setup my mail queue.
on my route:
Route::get('/test-mail', function () {
Mail::to('***********#xxxx.com')->queue( new App\Mail\testMail());
echo "sent";
});
the mail is queued and stored in the DB and with my listener, i can see it is processed successfully but the mail for reasons i don`t know, is not received at my mailbox.
enter image description here

No Data in Sent Items when sending email using Laravel and IBM Notes

Good day.
I am currently using Laravel 5.3 Mailer and an IBM notes email account.
I was able to successfully sent emails but when I looked at the sent items of the email that I used for sending, there was none.
I am currently using this configuration in .env
MAIL_DRIVER=smtp
MAIL_HOST=ourhostip
MAIL_PORT=25
MAIL_USERNAME=myaccount
MAIL_PASSWORD=mypass
MAIL_ENCRYPTION=
In my controller I am using this code.
$data = "Testing Data";
$email = "email";
$name = "Name";
Mail::send('emails.reminder', ['data' => $data], function ($mail) use ($name,$email) {
$mail->from('fromemail', 'AI');
$mail->to($email, $name)->subject('Testing Email!');
});
Any help would be appreciated. Thanks.
This is just the way SMTP works. When you use Outlook,Thunderbird, etc. to write an email via SMTP and your Notes/Domino Account you can see the E-Mail in your Notes Sent Folder only if you configure an IMAP Connection too.
I'm afraid this is not posible in Laravel.
If you want to have the E-Mail in your IBM Notes Inbox you can send the mail with BCC to your own address (and move it with a mail rule to a folder).

How to change header information of mail in Laravel?

I am creating a simple contact us form using Laravel 5.1
public function sendMessage(){
$data = [
'name' => Input::get('name'),
'email' => Input::get('email'),
'subject' => Input::get('subject'),
'body' => Input::get('body')
];
Mail::send('emails.contact',$data, function($message) use($data){
$message->from($data['email'], $data['name']);
$message->to('smartrahat#gmail.com','Mohammed');
$message->subject($data['subject']);
});
Session::flash('success_message','Mail sent successfully!');
return redirect('contact');
}
Everything is working fine but the sender email address is not the one it get from the contact page. The email is sent from the address which I configure in .env
I want to have the email from the sender email address which he filled up contact form. Or, you can say I want to change the header information (only from, I can change other information).
Well Laravel will send the mail through the given smtp server. I guess the smtp server (e.g. google doing this) will not let you change your from address to another address then the account belongs to.
If you want to reply to this address directly in your email programm you can add $message->replyTo($data['email'], $data['name']);.
The $message variable inside the Mail::send() function is a SwiftMailer message instance. Therefore, you can work with headers just like the SwiftMailer documentation shows. Just use $message->getSwiftMessage() to get and manipulate the headers.
Also, you absolutely can change the From header, but if you change it to a different domain, you'll have to deal with phishing warnings in the client. You can resolve that by setting up DKIM and SPF records, and you will need to have access to the DNS settings for the domain to do that.

Can't send email via SMTP because "550 - Relay Not permitted"

I'm using CakePHP to send automated emails to clients. It's been working great, but it seems some recipients aren't receiving our emails. So I decided to use the SMTP option for sending emails, and route emails through our email provider at Media Temple.
However, when trying to send email from a Media Temple account, I get the error "550- relay not permitted".
That sounds like the Media Temple server is just plain not allowing me to send mail through it.
That's odd because I've confirmed the username and password I'm using is correct and I can send mail via SMTP through it from my macmail client and iPhone mail client. I've also confirmed my cakephp email settings are correct, because I can send emails via SMTP with a gmail account with the exact same configuration in cakephp.
Any idea why I'm getting this error and how to resolve it?
Thanks
Here's the code that handles sending an email. I use this class just like the regular EmailComponent from within many different controllers.
class CanadafindsEmailerComponent extends EmailComponent
{
...
function send($content = null, $template = null, $layout = null) {
if(!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && is_array($this->bcc))
$this->bcc[]=TECHY_MONITOR_EMAIL;
else if (!in_array(TECHY_MONITOR_EMAIL,$this->bcc) && !is_array($this->bcc))
$this->bcc=array(TECHY_MONITOR_EMAIL);
if(DEVSITE){//commented-out code are settings for smtp with gmail, which works fine
$this->delivery = 'smtp';
$this->smtpOptions = array(
'port'=>'465',//'465',
'timeout'=>'30',//'30',
'auth' => true,
'host' => 'ssl://mail.thenumber.biz',//'ssl://smtp.gmail.com',
'username'=>USERNAME,//'USERNAME#gmail.com',
'password'=>SMTP_PASSWORD//,
);
$this->to=$this->correctFormatOn($this->to);
$this->bcc=$this->correctFormatOn($this->bcc);
$this->cc=$this->correctFormatOn($this->cc);
$this->replyTo=$this->correctFormatOn($this->replyTo);
$this->from=$this->correctFormatOn($this->from);
}
return parent::send($content,$template,$layout);
}
function correctFormatOn(&$email){
if(is_array($email)){
$copiedEmail=array();
foreach($email as $singleEmail){
$copiedEmail[]=$this->correctFormatOnSingle($singleEmail);
}
$email=$copiedEmail;
}else{
$email=$this->correctFormatOnSingle($email);
}
return $email;
}
function correctFormatOnSingle(&$email){
$subEmails=explode(",",$email);
$fixedSubEmails=array();
foreach($subEmails as $subEmail){
$fixedSubEmails[]=preg_replace('/<?([^< ]+)#([^>,]+)[>,]?/i', '<$1#$2>', trim($subEmail));
}
$email=implode(",",$fixedSubEmails);
return $email;
}
}
The main problem I was having was that clients weren't receiving emails from our server, (and so I wanted to use an SMTP server to see if that would fix it, instead of the server's default email server).
But I managed to get those clients to receive emails from the server by making some other changes, thus removing the need to use SMTP and the Media Temple email server.
(As an FYI, I found that we were getting bouncebacks from client email servers stating Diagnostic-Code: smtp; 550 Access denied - Invalid HELO name (See RFC2821
4.1.1.1), but they were being sent directly back to the server, and going into the linux user account "www-data". (I read them in /var/mail/www-data, just using tail and vim). I found that postfix, which was handling the sending of emails, was marking the email sender's hostname (ie, "HELO name") as canadafinds3, the name I gave the server in Rackspace, not the domain name: canadafinds.com. So I changed that in /etc/postfix/main.cf, restarted postfix, et voila! No more bouncebacks from those particular clients, and everyone's happy again.)
I ended up writing my own PHP mail() script based on https://web.archive.org/web/20180401094709/http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/ in order to circumvent this error.

Categories