Add Header Flag in YiiMailer - php

Problem
While Sending Mail via Postfix and through Amazon SES it throws me a ,
554 Message rejected: Email address is not verified.
Error message, And i have verified my From Email address and Amazon SES is in the production environment , so no issue there. This is what Amazon documentation says :
Email address is not verified—Your account is in the sandbox and one
of the recipient email addresses has not been verified. This might
apply to "Sender", "Return-Path", or "From" addresses.
If you have not requested production access to Amazon SES, you must
verify every recipient email address except for the recipients
provided by the Amazon SES mailbox simulator. You must also verify
your own "From" address. For more information, see Verifying Email
Addresses and Domains in Amazon SES and Testing Amazon SES Email
Sending.
SO, After searching for solution i found out a BLOG POST explaining the fix for this issue, which says adding -f flag in email will solve this issue,
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: michael#chtoen.com' . "\r\n" .
'Return-Path: michael#chtoen.com' . "\r\n" .
'Reply-To: michael#chtoen.com' . "\r\n";
mail($to, $subject, $message, $headers, '-f michael#chtoen.com');
?>
Which actually does solve the issue, But I cannot set it to the YiiMailer. For now i am adding this flag directly to php.ini as ,
sendmail_path to usr/sbin/sendmail -t -i -f "noreply#sbworkbench.com"
It works fine. But I don't want to do it this way.
What I have done
Is , Create the YiiMailer setup as ,
$mail = new YiiMailer('customerEmail', $data);
Common::setup_smtp($mail);
$mail->setLayout('mail');
$mail->render();
$mail->From = Yii::app()->params['adminEmail'];
$mail->FromName = 'PENDING NOTIFICATION';
$mail->Subject = $data['subject'];
$mail->AddAddress($data['sendTo']);
And for adding the flag I have tried ,
Adding the flag itself in the From address : Results the same
invalid email
$mail->From= "-f exaple#example.com"
Adding extra parameters "Form" with value as "-f exaple#example.com" : Results Duplicate Form Address (which is obvious :D)
Question :
How can I set header flag using YiiMailer ?
Is it related to misconfiguration of Postfix with Amazon SES ? However, The same setting is working fine for Java Application.
P.S
The code works on sendmail and swiftmail without Amazon SES with no
need of the header flag.

YiiMailer is a wrapper for PHPMailer. You can set the -f flag by setting the $Sender property of PHPMailer.
$mail->Sender = "michael#chtoen.com"

Related

Sending e-mail from a local host

I am trying to send an email from localhost, and the program I am using is MAMP. I have looked this up online and done everything written, but this still won't work. The function I have entered in my PHP file to send emails is:
mail(
$admin_email, $messaage,
'Works!',
'An email has been generated from your localhost, congratulations!');
furthermore, I have filled out all the send mail value as shown below:
smtp_server=smtp.gmail.com
; smtp port (normally 25)
smtp_port=25
smtp_ssl=ssl
auth_username=****#gmail.com
auth_password=*******
hostname=localhost
Obviously - my email and password are filled out using my email and password. Also I have altered the php.ini file as shown:
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
;http://php.net/sendmail-path
sendmail_path = C:\Windows\System32\sendmail\ -t -i -f my_email#gmail.com
Can someone tell me where my error is?
You're not going to be able to send via Google's SMTP server because the mail() function doesn't perform SSL or TLS authentication, which is required. See this answer for more information. You should consider using the PHPMailer class instead.
Also, please note that you're using mail() incorrectly. You have
mail(
$admin_email, $messaage,
'Works!',
'An email has been generated from your localhost, congratulations!');
The second argument should be a subject, and the third should be the message. The fourth argument is optional and is supposed to contain extra mail headers:
additional_headers (optional)
String to be inserted at the end of the email header.
This is typically used to add extra headers (From, Cc, and Bcc). Multiple extra headers should be separated with a CRLF (\r\n). If outside data are used to compose this header, the data should be sanitized so that no unwanted headers could be injected.
It is not for a plaintext message like you are using. By adding plaintext where a properly-formatted header should be, you are likely to break some servers and some mail readers.
If you are using smtp_port=25you have to change smtp_ssl=none or use this
smtp_port=587
smtp_ssl=tls
Have you changed these settings from your gmail account
Access your email account. Click the Gear Tool > Settings > Forwarding
and POP/IMAP > IMAP access. Click "Enable IMAP", then save your
changes
For check email use these code
<?php
$to = 'myemail#yahoo.com';
$subject = 'Fake sendmail test';
$message = 'If we can read this, it means that our fake Sendmail setup works!';
$headers = 'From: myemail#egmail.com' . "\r\n" .
'Reply-To: myemail#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if(mail($to, $subject, $message, $headers)) {
echo 'Email sent successfully!';
} else {
die('Failure: Email was not sent!');
}
?>

Do we really need -f flag in PHP mail? Why?

I've always included -f flag in my php applications because I thought it is important as the documentation told us:
The user that the webserver runs as should be added as a trusted user
to the sendmail configuration to prevent a 'X-Warning' header from
being added to the message when the envelope sender (-f) is set using
this method. For sendmail users, this file is /etc/mail/trusted-users.
So it looks like it is used to prevent spoofing - by verifying who I am. Then I did a experiment. It turns out, if I do not include -f, there will still be no X-Warning when I send mails. In fact, the sender doesn't even need to be myself. For example, I tried Obama#whitehouse.org as sender, and I received the email with no warning. I even tried using Obama#whitehouse.org to send out a few hundreds of emails to multiple email accounts, and they didn't get flagged as spam.
So, my question is, what does -f flag really do (since it seems to me that without it, emails will send through just fine)?
The -f flag is used to specify the envelope sender address. You should use the -f flag to set this address so that it matches the FROM address in the headers of the message, otherwise some spam filters will be more likely to treat the message as spam due to the fact that the two do not match.
You can do something like the following to set both, so that they match:
$to = "to#to.com";
$from = "from#from.com";
$subject = "subject";
$message = "this is the message body";
$headers = "From: $from";
$ok = #mail($to, $subject, $message, $headers, "-f " . $from);

PHP mail function can't send out email when I added .com.sg instead of just .com

I want to send out a link for user to verify their account after they register. But when I use www.singapore.com at the $message I am able to receive the email, but when I change it back to www.singapore.com.sg I can't receive it. I wonder is it because of the link or there is some error in my codes? Please help me.
$domain ='www.singapore.com';
$id = mysql_insert_id();
$to = 'myemail#gmail.com';
$subject = "E-mail Verification";
$message = 'Click on the link to verify your account: http://'.$domain.'/rates/activation.php?id='.$id.' ';
$headers = "From: <Singapore> \r\n";
mail($to,$subject,$message,$headers, '-f enquiry#singapore.com.sg');
Do you need the -f envelope option? If memory serves, any address put in there needs to be already added as a trusted user in the sendmail configuration.
I found this on the PHP mail docs:
The user that the webserver runs as should be added as a trusted user
to the sendmail configuration to prevent a 'X-Warning' header from
being added to the message when the envelope sender (-f) is set using
this method. For sendmail users, this file is /etc/mail/trusted-users.
Are you simply trying to set the reply to and from addresses? If so, use the $header for that and don't bother with the additional parameters.
$headers = “From: enquiry#singapore.com.sg” . “\r\n” . “Reply-To: enquiry#singapore.com.sg”;
Something is wrong with your code. Change it to this
$message = 'Click on the link to verify your account: http://'.$domain.'/rates/activation.php?id='.$id;
It has extra quotes at the last.
Hope that helps.. :)

Hide server when sending email from mail php function

All,
I have the following code:
$to = $friend_email[$x];
$subject = "Subject";
$message = "This is a message";
$from = $your_email;
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
When the email sends (I'm using Godaddy's hosting service) it says From correctly but then in gmail it says via pxnlhgxxx.prod.xhx3.secureserver.net. Is there anyway to hide the via part or make it say something like website.com? Thanks for the help.
As per the mail() docs, you use the optional 5th parameter for the function and pass in the name of the server you'd like to masquerade as:
mail($to, $subject, $message, $headers, "-f sender#website.com");
If your hosting off godaddy then something like that will happen. You can use your own SMTP server, or use Google free SMTP Server (logging in with your gmail account). Host Gator does the same thing.
You can prevent Google from showing the 'via' notice by DKIM signing your outgoing mail to prove that you genuinely control the domain you're sending e-mail on behalf of.
Its all up to the configuration of the smtp server.

PHP mail not showing up at Gmail but shows up at Hotmail and other 3rd party/ISP account

I have 2 sites where mail is sent to two vanity gmail accounts. I'm using PHP to handle the mail, but the mail is not showing up at gmail (not in spam/junk, it just doesn't show up). If I switch the PHP to send to my personal hotmail account, the mail shows up. Same for a personal email account through my ISP.
The mail used to show up at those 2 vanity gmail accounts, any ideas why they would just stop?
There is a possibility you did not set proper header data, and those emails are blocked even before reaching spam folder.
Try adding something like this:
$headers = 'From: your#email.com' . "\r\n" .
'Reply-To: some#email.com';
This is the fourth parameter of mail() function.
I have encountered problems in the past where certain free email providers would not receive any email from my servers.
I found that a few things can be the culprit, on top of putting the correct headers in the actual message:
Make sure your server is configured for reverse dns lookup
Make sure you are not running an open smtp relay
Make sure your server did not wind up in any email blacklists (if you had an open relay, you probably got blacklisted.
Chances are, PHP is sending the email just fine, but the Google servers are rejecting any messages coming from your server.
You can test this by doing a quick:
mail -s Test you#gmail.com < /dev/null
If your server is okay, you will receive a message in your gmail, if you don't, PHP isn't the problem.
I've found having a proper SPF record for your domain really helps
http://www.openspf.org/SPF_Record_Syntax
Seems more likely that this is a server configuration issue and not a PHP issue.
As a side note I've found gmail more tolerant than our local system, so I've been able to get messages out to my gmail account, but not my account on the hosting domain.
I don't think Google uses third-party black lists, but they do care about server configuration (does it identify itself correctly, have matching SPF and RDNS records, respond to commands properly). You might try a couple of testing services like this or this.
I see it is too late but ... following code is working for gmail.
<html>
Mail Responder:<br><br>
<?php
$to = $_REQUEST['MyEmail'] ;
$subject = $_REQUEST['subject'] ;
$greeting = $_REQUEST['greeting'] ;
$realname = $_REQUEST['realname'] ;
$HisEmail = $_REQUEST['HisEmail'] ;
$message = $_REQUEST['message'] ;
$headers = 'From: '.$HisEmail;
//$headers = 'From: $HisEmail' . "\r\n" .
//'Reply-To: some#email.com';
$send = mail($to, $subject, $greeting."\n"."\n".$realname."\n"."\n".$HisEmail."\n"."\n".$message, $headers );
if ($send)
$mailReturns = "Mail sent successfully.";
else
$mailReturns = "Mail sent failed.";
?>
<?php echo $mailReturns; ?>
</html>

Categories