How to set up headers "Reply-to" in Mailgun php API?
I've using this code but can't imaging hot to set up headers
Mail::send('email.message', $data, function ($message) use ($data) {
$message->to($data['to_email'], $data['to_name'])
->subject($data['subject'])
->from($data['from_email'], $data['from_name']);
});
It's as simple as adding a replyTo on your $message chain
Mail::send('email.message', $data, function($message) use($data)
{
$message->to($data['to_email'], $data['to_name'])
->subject($data['subject'])
->from($data['from_email'], $data['from_name'])
->replyTo('REPLY.TO.THIS#email.com');
});
if you want to add a name to the reply to, just add another parameter with the name:
->replyTo('REPLY.TO.THIS#email.com', 'Arsen Ibragimov')
Related
i am working in laravel 5.6 and i use mail function that is:
Mail::send('mail.tes', ['data' =>$userregister ], function($m) use ($userregister){
$m->to($userregister['email'])->subject("Testing email auto konfirm")->getSwiftMessage()
->getHeaders()
->addTextHeader('x-mailgun-native-send', 'true');
});
then i got error
Swift_TransportException
Process could not be started [The system cannot find the path specified. ]
and dont have idea where or what is the path specified?
try this:
Mail::send('mail.tes', ['data' => $userregister ], function($m) use ($userregister){
$m->to($userregister['email'])->subject("Testing email auto konfirm");
$m->withSwiftMessage(function ($message) {
$message->getHeaders()
->addTextHeader('x-mailgun-native-send', 'true');
});
});
I am trying to use Mail function in Laravel. Heres the code
public function basic_email(){
$data = array('name'=>"Virat Gandhi");
Mail::send(['text'=>'mail'], $data, function($message) {
$message->to('shanipasrooria#gmail.com', 'Tutorials Point')->subject
('Laravel Basic Testing Mail');
$message->from('m.usman5991#gmail.com','Virat Gandhi');
});
echo "Basic Email Sent. Check your inbox.";
}
I have made changes in .env file. Set everything, Heres my route.
Route::get('sendbasicemail','MailController#basic_email');
I get the following Error.
InvalidArgumentException in FileViewFinder.php line 137:
View [mail] not found.
You can try this code
Mail::send([], [], function ($message) {
$message->to('shanipasrooria#gmail.com', 'Tutorials Point')
->subject('subject')
->setBody('some body', 'text/html');
});
you can try this
$html = '<h1>Hi, welcome Virat!</h1>';
Mail::send([], [], function ($message) use ($html) {
$message->to('shanipasrooria#gmail.com', 'Tutorials Point')
->subject('Laravel Basic Testing Mail')
->from('m.usman5991#gmail.com','Virat Gandhi')
->setBody($html, 'text/html'); //html body
or
->setBody('Hi, welcome Virat!'); //for text body
});
Mail::send(['text'=>'mail']< here the mail should be a valid view file.
According to API Documentation, the Mailer Class should receive a String, Array Or MailableContract, Those reference a view. So you need to pass a valid view in the send method.
void send(string|array|MailableContract $view, array $data = [], Closure|string $callback = null)
I have provided host ,username ,password,port no. in .env and config/mail.php. I am sending email from localhost.
public function sendEmail(){
$data = array('name'=>"Swati Jadhav");
$arrCategory=Category::getCategory();
Mail::send('frontend.welcome',['arrCategory'=>$arrCategory] ,$data, function($message) {
$message->from('sender#gmail.com', 'text');
$message->to('receiver#gmail.com', 'text')->subject('Welcome!');
});
}
Mail::send needs the callback as the 3rd parameter (not 4th). If you need to combine two parameter arrays you can do:
Mail::send('frontend.welcome',array_merge(['arrCategory'=>$arrCategory] ,$data), function($message) {
$message->from('sender#gmail.com', 'text');
$message->to('receiver#gmail.com', 'text')->subject('Welcome!');
});
I'm making a contact form. If someone fills in the form, the data (text,subject) should be sent to my mail. Everything works, but when I fill in form and send the email, it sends the whole HTML page (not just the text from the form).
Here's how it looks like
Here's my controller where I send the mail
public function sendEmail(Request $request)
{
$data["username"] = $request->username;
$data["email"] = $request->email;
$data["subject"] = $request->subject;
$data["mail_text"] = $request->mail_text;
Mail::send('contact', ["data" => $data], function ($mail) use ($data){
$mail->to("leribobo#gmail.com")->from($data["email"])->subject($data["subject"]);
});
return redirect()->back();
}
as I guess it sends 'contact' page, which is first parameter in method
Mail::send('contact' ....
You are actually sending the contact.blade.php file. This is not how we should send a mail.
Mail::send('emails.contact', $data, function ($message) {
//
$message->from('us#example.com', 'Laravel');
$message->to('foo#example.com')->cc('bar#example.com');
});
You've to make a file in emails.contact.blade.php and pass $data to the blade file as showed above.
Check here: https://laravel.com/docs/5.1/mail#sending-mail
This is my code:
$email = "email#gmail.com";
$data = array(
'email' => $email,
'async' => false,
);
Mail::queue('user.mails.welcome', $data, function($message) use ($email) {
$message
->to($email, $email)
->subject('Welcome to the Laravel 4 Auth App!');
});
And this is what shows on my Mandrill account API log:
Full Request {
"key": "x",
"raw_message": "y",
"async": "1"
}
Full Response {
"email": "xy",
"status": "queued",
"_id": "z"
}
As you can see, emails are being queued by default. Why? And how can I change that?
Per the Mandrill docs:
Async: enable a background sending mode that is optimized for bulk sending. In async mode, messages/send will immediately return a status of "queued" for every recipient. To handle rejections when sending in async mode, set up a webhook for the 'reject' event. Defaults to false for messages with no more than 10 recipients; messages with more than 10 recipients are always sent asynchronously, regardless of the value of async.
Basically, it's something that Mandrill is doing on their end is is unrelated to whether you use Mail::send or Mail::queue in Laravel.
All emails sending through Mandrill are queued and sent out in accordance with the parameters defined for your account. In other words: They decide when your emails eventually get sent.
Edit: Laravel's Mandrill Mail Transport is always going to send with async mode enabled. There's no way to configure that without editing the class: MandrillTransport
I am not sure I understand. Your emails are being queued because you are using the queue() method:
Mail::queue('user.mails.welcome', $data, function($message) use ($email) {
If you want to not queue, then use the send() method:
Mail::send('user.mails.welcome', $data, function($message) use ($email) {
I had to set a "from" email to have this work.
The 'async' parameter of the mandrill api isn't exposed to the Laravel mail closure. I just extended the MandrillTransport class and passed a Swift_Mime_Message into it so that I could capture the response, it will be 'sent' or 'rejected' (and reject_reason will be populated with something like "hard/soft bounce") which I can store in my application:
class Mandrill extends MandrillTransport
{
public function send(\Swift_Mime_Message $message, &$failedRecipients = null)
{
$client = $this->getHttpClient();
$response = $client->post('https://mandrillapp.com/api/1.0/messages/send-raw.json', [
'body' => [
'key' => $this->key,
'raw_message' => (string)$message,
'async' => false,
],
]);
return $response->json();
}
}