I'm sending emails with cakephp and I have been testing it with the followign website:
http://spamcheck.postmarkapp.com/
I have had several problems, which one of them was the encoding of the subject.
Right now, that one is solved, following some solutions I've found in the internet. First line of the code is what i'm doing with the subject
Here's my code:
$newsubject='=?UTF-8?B?'.base64_encode($subject).'?=';
$email = new Email('aws');
$email->from(['xxxx#zzzz.zz' => 'test'])
->template('default','confirmation')
->viewVars([
'user_email' => $emailTo,
])
->emailFormat('both')
->to($emailTo)
->subject($newsubject)
->replyTo('support#uphill.pt')
->helpers(['Html', 'Text'])
//->attachments($attachment->path)
->send($message);
After I recieve the email, the subject shows: "=?UTF-8?B?SW5zY3Jpw6fDo28gbm8gZXZlbnRvOiBOYXRpb25hbCBDb25mZXJlbmNlIG9uIEh1bWFuIFBhcGlsbG9tYSBWaXJ1cw==?="
What am I missing?
EDIT:
I'm using Cakephp 3.3 and here's my aws email transporter config
'aws' => [
'transport' => 'aws',
'from' => 'xxxx#zzzzz.z',
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
]
Here's my email:
http://pastie.org/private/hzcicqrlzx425ucanxyl5a
Thanks
About the result :
You encoded the email Subject text with base64.
So, you get the encoded text from your Subject plain text.
You should use email Subject as string/plain text. Mail services doesn't decode your custom encode type automatically.
Change your Subject string :
$newsubject='=?UTF-8?B?'.base64_encode($subject).'?=';
#TO
$newsubject=$subject;
Search by typing EmailTransport or Email from config/app.php and check your email configuration is correctly configured.
Her is the details about CakePHP 3.x Email
Related
I'm using mailgun to sending email, but I'm not able to send more emails (if I duplicate the code below and add change 'to' variable) or I am not able to send cc. If I remove 'cc' from the code, everything works fine, oherwise it throws error pasted below:
$result = $mgClient->sendMessage($domain, array(
'from' => 'Me <me#domain.com>',
'to' => $_POST["customer"]["email"]),
'cc' => 'me#domain.com',
'subject' => 'Confirmation – domain.com',
'html' => $text
));
error:
Fatal error: Uncaught Mailgun\Connection\Exceptions\MissingRequiredParameters: The parameters passed to the API were invalid. Check your inputs! The domain is unverified and requires DNS configuration. Log in to your control panel to view required DNS records.
There is no problem with your code.
The error is for an unverified domain name. You used domain.com as domain, make sure this domain name is verified and valid.
for more read this
This is my code:
Mail::send('view',$dataView, function($message) use ($user)
{
$message->from('my_email#gmail.com', 'Myname');
$message->subject('This is title');
$message->to(sender_email#gmail.com, $user->user_username);
});
It works! But When I check sender_email#gmail.com then I see "from email" which I config in .env ( MAIL_USERNAME ), it isn't "from email" in code (my_email#gmail.com), How to I can change it to my_email#gmail.com? Thanks and sorry about my english.
In config/mail.php, around line 58, try changing:
'from' => [
'address' => 'hello#example.com',
'name' => 'Example',
],
to:
'from' => [
'address' => env('MAIL_USERNAME'),
'name' => env('MAIL_USERNAME')
],
You are trying to send emails via dynamic senders which is not allowed by Gmail for preventing spamming mails, so automatically Gmail will change your sender address to your default address.
I guess you're misunderstanding the MAIL_USERNAME which is in your .env file.
So basically, Laravel provides simple solution to send emails via dynamic senders. Lets say you've signed up for MailGun or SendGrid to send mails and MAIL_USERNAME is the username for your mail provider not your sender mail address. (Not Gmail, as Gmail doesn't support dynamic senders. Its good if you're testing your mails.).
so, you're .env will look like this.
MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=sendgridUsername
MAIL_PASSWORD=sendgridPassword
MAIL_ENCRYPTION=tls
Now, you're eligible to send mails using sendgrid. Now Lets say your domain is example.com so you can use admin#example.com support#example or any email address with your domain to send emails.
To Receive messages either you use webmail or Gmail.
Hope this helps.
I am using Mailgun to handle email in my Laravel 5.1 application. There are times when I need to email a large number of users at once, such as internal group emails and alert notices. So far, I have created an array of recipient email addresses, sent the email to a webmaster type address, and included the end recipients in BCC:
$recipients = [];
foreach (User::emailRecipients()->get() as $user)
{
$recipients[] = $user->email;
}
$data['message'] = "Hello World";
$data['recipients'] = $recipients;
Mail::send('emails.group-email', $data, function($message) use ($data) {
$message->to('support#demo.com')
->bcc($data['recipients'])
->subject('Test message');
});
While this works, it's not ideal. For starters, I cannot reference anything unique to each recipient within the email (such as a custom unsubscribe link). I cannot use some sort of mailing list on an email provider because the recipients will never be the same, it all depends on several factors.
The next logical step is to iterate over each email address and use Mail::send on each iteration. But would this cause any performance issues or API restrictions with Mailgun? It's possible that one email could be sent to approximately 200 recipients.
Rather than using Laravel's built in Mail, I elected to use Mailgun's API (specifically batch sending) directly - mailgun/mailgun-php
$mailgun = new Mailgun('API-KEY');
$recipientVariables = [
"someone#demo.com" => ['name' => 'Benny'],
"someoneelse#demo.com" => ['name' => 'James']
];
$mailgun->sendMessage('demo.org', [
"from" => 'support#demo.org',
"to" => 'someone#demo.com, someoneelse#demo.com',
"subject" => 'Cool Email',
"html" => $content, // HTML from Blade template
"text" => "Plain text message",
"recipient-variables" => json_encode($recipientVariables)
]);
This also allows me to access unique recipient variables within my email template, like so:
<h1>Hello, %recipient.name%</h1>
I was already passing my Blade template through a CSS inliner, which turns it into plain HTML, so this works perfectly.
I have configured my mail.php config file to send emails using the gmail account.
Everything looks great, but when I try to send email from another account (not the address used in the mail.php config file) I get an email from the address set on the configuration file.
Mail::send('emails.contact_mail', array(
'email' => $fromEmail,
'name' => $user,
'subject' => $subject,
'message' => $message_content,
), function($message)use ($fromEmail,$user,$subject) {
$message->to('s111#gmail.com');
$message->from('test#gmail.com', $user);
$message->subject($subject);
});
It seems like the $message->from doesn't work. I get on the s111#gmail.com an email from the address set in mail.php file and not from test#gmail.com.
Is there any solution? How to change the from address?
You will still use the SMTP servers set in your config file. Setting another 'from' header is theoretically possible, but the GMail SMTP will ignore it unless you set an address that has been added to your Google account.
Solution: either don't use another 'from' address, or add that address to your Google account.
There are a couple things you can try:
$message->replyTo('test#gmail.com', $user);
And to my understanding, the "From: " header in emails is what should determine what it will display as the sender. This may work for changing the "From" header:
$message->getHeaders()->addTextHeader('From', 'Your Name <test#gmail.com>');
I think this is best solution for this question.
We can figure out this as follows:
$message->from('sender#email.com', 'sender_name');
And also we should remove the following code block in config/mail.php.
'from' => [
'address' => 'sender#email.com',
'name' => 'sender_name',
],
of course, this will be working on Laravel Framework.
I can currently send email but for some odd reason the from message looks like this...
noreply=myWebsite.com#mailgun.org <noreply=myWebsite.com#mailgun.org>
But my config file reads as follows...
'driver' => 'mail',
'host' => '',
'port' => 587,
'from' => array('address' => 'noreply#myWebsite.com', 'name' => 'My Website'),
'encryption' => 'tls',
I thought mail was just native php email. I am just trying to understand why it still references mailgun despite the removal of smtp as driver.
What I noticed on the actualy email I receive it says that its from "My Website" followed by "sent by noreply=myWebsite.com#mailgun.org". If I click respond to "My Website" the email address is correct "noreply#mywebsite.com". I just don't understand why I can't get it not to show the sent by message. Any advice?