PHP mail use FROM of multiple mail client (Yahoo | Google | Hotmail | Rediff | Personal Mail domain)

淺唱寂寞╮ 提交于 2020-01-25 19:00:10

问题


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


来源:https://stackoverflow.com/questions/40631734/php-mail-use-from-of-multiple-mail-client-yahoo-google-hotmail-rediff-p

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!