I have the following code:
Mail::send('emails.welcome', $data, function($message) use ($user){
$message->from('xxx#xxx.xxx', 'XXXXX');
$message->to($user['email'], $user['name'])->subject('Welcome to My Laravel app!');
});
Now, it doesn't matter what I put in the email template (emails.welcome) the email message is always blank!
Does anyone have any idea why this is happening?
go to app/config/mail.php
in line 57
'from' => array('address' => null, 'name' => null),
set the value for the address and name
Related
I use mailgun and integrated with php. The mail sends fine without error. I create a default template in mailgun(Action Template). In that template there is a button. My Issue is
How to i pass a parameter to that button a tag
MY code is
$mg = Mailgun::create('MY API');
// Now, compose and send your message.
$result = $mg->messages()->send('MY DOMAIN NAME', [
'from' => 'support#figjam.net',
'to' => $email,
'subject' => 'Confirm Your E-mail',
'html' => ' <p>Please confirm your email address by click the link below <br>
<button type="button" class="btn btn-secondary">CLICK TO ACTIVATE YOUR ACCOUNT</button></p>'
'template' => 'verifyemail'
]);
I need to pass variable to that template verifyemail
Kindly Help me fix this.
Thanks
Let's assume you have myvariable with value someVariableValue
'template' => 'verifyemail',
'v:myvariable' => 'someVariableValue',
]);
Im trying to figure out how to quickly add error messages per field in Laravel 5. Here is what I got:
$validator = Validator::make($this->req->all(), [
'email_add' => 'required|email|max:100',
'pass' => 'required|max:20',
]);
So how do I put a message directly here for each field validated above? like "You forgot Email Address" and "Password is Required"?
(How to that without writing a mars rover program for 1 simple task. Like the usualy laravel 5 stuff of artisan make new something useless, add 2 namespaces, 3 middlewares, 5 classes, 7 functions and then finally override error messages!!)
[EDIT]
After some help from answers below and other search on stack, I found exactly what is to be done:
Add a message for the type of validations per field:
$validator = Validator::make($this->req->all(), [
'email_add' => 'required|email|max:100',
'pass' => 'required|max:20',
], [
'email_add.required' => 'The Email Address is actually required dude!',
'email_add.email' => 'The Email Address is is not a valid Email Address!'
]);
.
.
To just change the email_add into Email Address, i.e. the Attribute Name instead of writing a custom msg for every validation applied on every field:
Validator::make(....)->setAttributeNames(
[
'email_add'=>'Email Address',
'pass'=>'Password'
]);
Thanks for the help guyz.
try this its work for you
$validator = Validator::make($this->req->all(), [
'email_add' => 'required|email|max:100',
'pass' => 'required|max:20',
]);
$messages = [
'email_add.required' => 'You forgot Email Address',
'pass.required' => 'Password is Required',
];
To do so, add your messages to custom array in the resources/lang/xx/validation.php language file.
'custom' => [
'email' => [
'required' => 'We need to know your e-mail address!',
],
],
https://laravel.com/docs/5.1/validation#custom-error-messages
if you want to change validation message for specific request you can put messages method within same request file like this
public function messages() {
'name.required' => 'custom message',
'email.required' => 'custom message for email',
'email.email' => 'custom message form email format'
}
Or if you want put validation message inside controller just pass third parameter as a message.
This question already has answers here:
How to change from-address when using gmail smtp server
(6 answers)
Closed 6 years ago.
I'm trying to send a very basic email in Laravel but the from field is not working. Instead of it being from the sender with their return address, it has MY return address and their name.
My .env has
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=chris#listingnaples.com
MAIL_PASSWORD=mypass;
MAIL_ENCRYPTION=tls
My controller has:
public function sendEmail(ShowingPageContactRequest $request) {
// email me custom email
$data = $request->all();
Mail::send('emails.propertyemail', $data, function ($message) use ($data) {
$message->subject('Property Query from ' . $data['name'])
->sender($data['email'], $data['name'])
->from($data['email'], $data['name'])
->to('chris#listingnaples.com')
->replyTo($data['email'], $data['name']);
});
}
A dd($data) shows:
array:6 [▼
"_token" => "ZSvuhAhkCetDFZOrQMtbDHBy2RfzECGFT03wixt3"
"MLSNumber" => "216003681"
"name" => "John Doe"
"email" => "jdoe#gmail.com"
"phone" => "(239) 555-1212"
"comments" => "This is my comment or question."
]
So the email is there and John Doe is there. However, when I check my email it says it is from John Doe but chris#listingnaples.com!
My mail config file even has:
'from' => ['address' => null, 'name' => null],
Adding your own Reply-To appears to be as close as it's going to get.
In Laravel 5 you can add a Reply-To using $message->replyTo ($address, $name)
See this answer and this support page, unless you added all your users manually I don't think it will work.
Other email services will let you do this, I think SendGrid does, if I recall correctly.
Im trying to send an email and im using mailtrap for this. the email im trying to send is just a plain messgae let's say , "You have been emailed!" but i can't seem to make it using laravel 4.2 here is my mail.php
return array(
'driver' => 'smtp',
'host' => 'mailtrap.io',
'port' => 2525,
'from' => array('address' => 'example#gmail.com', 'name' => 'SSIMS'),
'encryption' => 'ssl',
'username' => 'sadasdadsadadsad', //not my real username
'password' => '341ssfsdf2342', //not my real password
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => false,
);
just copied this from mailtrap.io then i don't know how to send the email using laravel. The thing is im not sending any views im just trying to send some simple message so in the documentation of 4.2 i saw that there is this Mail::raw() method so i used it like this
then when i tried it i got an error saying
Call to undefined method Illuminate\Mail\Mailer::raw()
here is the controller that handles it (i omitted the other functions here)
<?php
class POrder extends \BaseController
{
/**
* Display a listing of the resource.
*
* #return Response
*/
public function index()
{
//
$title = "Purchase Order Page";
$modules = prchorder::lists('ModuleName','ModuleID');
return View::make('ssims.purchaseorder_index',compact('title','modules'));
}
public function chkInput()
{
session_start();
$getsCapt = $_SESSION["captcha"];
$rules = array(
'ModuleInfo' => 'required',
'Quantity' => 'required|numeric|digits_between:2,5',
'SchoolEmail' => 'required|min:10|max:254|email',
'SupplierEmail' => 'required|min:10|max:254|email',
'capt' => 'required|numeric'
);
$messages = array(
'ModuleInfo.required' => 'Please Select a Module.',
//'SchoolEmail.email' => 'Please Enter a Valid Email for the School Email.',
//'SupplierEmail.email' => 'Please Enter a Valid Email for the Supplier Email.',
'capt.numeric' => 'CAPTCHA code must be a number.',
'SchoolEmail.same' => 'School Email cannot be same with the Supplier Email.',
'SupplierEmail.same' => 'Supplier Email cannot be same with the School Email.',
);
$validator = Validator::make(Input::all(), $rules, $messages);
$uCapt = Input::get('capt');
// process the inputs given by the user
if ($validator->fails()) {
return Redirect::to('purchase_order')
->withErrors($validator)
->withInput(Input::except('password'));
} else {
if ($uCapt == $getsCapt) {
$sEmail = Input::get('SupplierEmail');
//return Redirect::to('purchase_order');
Mail::raw('Text to e-mail', function($message) {
$message->from('sample#gmail.com', 'Laravel');
$message->to('sample1#gmail.com')->cc('sample2#yahoo.com');
});
} else {
return Redirect::to('purchase_order')
->withErrors('CAPTCHA code does not match')
->withInput(Input::except('password'));
}
}
}
}
Any ideas on what i may be doing wrong? or how can i make it work? thanks
Given that Laravel 4.2 doesn't support Mail::raw(), simply replace it with Mail::send() like so:
Mail::send('emails.example', array('a_value' => 'you_could_pass_through'), function($message)
{
$message->to('sample1#gmail.com', 'John Smith')->cc('sample2#yahoo.com')->subject('Example!');
});
In this example, emails.example refers to a view called example in an emails folder with the rest of your views. array('a_value' => 'you_could_pass_through') is simply that - an array that passes data in to view. If you have no data you want to pass in then simply use array() as it is a required part of Mail::send().
The rest is just setting the to and cc fields, the from information will already come form your mail.php file which you have set up.
I'm trying to send a Mandrill email in the default Laravel 4 Mailer, and I want to set the template and send the data to Mandrill. I'd rather not use a local file in my Laravel, I have this all set up to work inside of Mandrill. This is how I have it set in Laravel:
Mail::send('emails.test',[],function($message)
{
$message->to(Input::get('email'), 'John Smith')->subject('Welcome!');
});
return
This sends an email from my "test" view inside of "emails" like it should. In vanilla PHP using the Mandrill library this would work to send to the template I want.
$message = array(
'subject' => 'Subject redacted',
'from_email' => $main_email,
'to' => array(array('email' => $to_email)),
'merge_vars' => array(array(
'rcpt' => $to_email,
'vars' =>
array(
array(
'name' => 'DETAIL',
'content' => $detail),
array(
'name' => 'ERROR_AMOUNT',
'content' => '$'.$trans_amount)
,
array(
'name' => 'CO_NAME',
'content' => $business_name),
array(
'name' => 'SMS',
'content' => $sms)
))));
$template_name = 'Test Email';
$template_content = array(
array(
'name' => 'main',
)
);
$response = $mandrill->messages->sendTemplate($template_name, $template_content, $message);
As an alternative, you could set the X-MC-MergeVars and X-MC-Template headers using Laravel's Mandrill functions.
Mail::send('emails.test', [], function($message) use ($mergevars)
{
$headers = $message->getHeaders();
$headers->addTextHeader('X-MC-MergeVars', json_encode($mergevars));
$headers->addTextHeader('X-MC-Template', 'my-template');
$message->to(Input::get('email'), 'John Smith')->subject('Welcome!');
});
Note that I haven't tested this - just going by what I read here: Using SMTP Headers to customize your messages.
You might need to use something other than addTextHeader - check with the Swiftmailer documentation to work out how to add the correct header type for the data you are setting.
It doesn't appear that this is possible using Illuminate\Mail\Mailer. It looks like the Mandrill transport specifically uses the send-raw Mandrill API endpoint.
This leaves you with two options: Implement your own transport and work within the Mailer, or work outside the Mailer system. If you're going to go with the latter, you'd probably be best off just using the official library.
If you want to implement your own transport, take a look at the Swift_Transport interface. It's not going to be a perfect match, since you're attempting to do something that the Mailer was never intended to do, but with enough hacking, you could get something up and running. You'd probably need to use undefined members on the Message class, like:
$message->template = "template_name";
$message->content = array(/* content here */);
$message->message = array(/* message here */);
// MandrilTemplateTransport.php
public function send(Swift_Mime_Message $message, &$failedRecipients = null)
{
$this->messages->send($message->template, $message->content, $message->message);
}
This is absolutely less than ideal, but a workable solution. I'd vote that you just use the Mandrill library outside of the Mailer system.