PHP mail use FROM of multiple mail client (Yahoo |

2019-06-07 10:53发布

问题:

Currently I'm Using PHP mail function Or CodeIgnitor mail function to send mail. From mail id can be of any domain , example xyz@gmail.com, xyz@yahoo.com, xyz@hotmail.com

Also To mail can be of any domain.

My mails are sent proper when FROM is set to any mail other than that of YAHOO. Having trouble to send mail from PHP mail FROM any mail of YAHOO. Is yahoo blocking my mails ?

How can I solve this problem ?

回答1:

You cannot send mail successfully on behalf of the domains stated above using your mail server. Each of those domains have something in use called an SPF (Sender Policy Framework) record in DNS which tells all recipients mail severs which check SPF to confirm the senders IP is the same as the SPF. You would need to send the email via their SMTP servers by relaying from your own.

SPF example for GMAIL & YAHOO

v=spf1 redirect=_spf.google.com
v=spf1 redirect=_spf.mail.yahoo.com

Check if an SPF record exists on domain by using this site:

http://mxtoolbox.com/spf.aspx

In my opinion, your best option is to relay your mail to the correct SMTP servers per domain. You can do this very easily using PHPMailer. If the domain set in the FROM option is a privately managed domain, then you should be able to relay on there behalf if no SPF record is set and your sending IP is not blacklisted.

A site for checking if your sending IP is blacklisted:

http://mxtoolbox.com/blacklists.aspx

An example of how you can choose which SMTP settings are used for a specific domain:

$email = 'xyz@yahoo.com';
$domain = explode('@', $email) ;

switch ($domain[1]) {

    case 'yahoo.com': 

          //NOT REAL SMTP SETTINGS!
          $mail->Host = 'smtp1.yahoo.com'; 
          $mail->SMTPAuth = true;                               
          $mail->Username = 'user@yahoo.com';                 
          $mail->Password = 'secret';                           
          $mail->SMTPSecure = 'tls';                           
          $mail->Port = 587;          

    break;

    case 'gmail.com': 

          //NOT REAL SMTP SETTINGS!
          $mail->Host = 'smtp1.gmail.com';
          $mail->SMTPAuth = true;                               
          $mail->Username = 'user@yahoo.com';                 
          $mail->Password = 'secret';                           
          $mail->SMTPSecure = 'tls';                           
          $mail->Port = 587;          

    break;


}


//Rest of PHP Mailer code