2014-09-26 76 views
1

我想为我正在开发的一个项目创造一个伟大的形式,但我正在努力争取“正确发送”属性。没有想法是什么与此,或者它只是想这样呢?PHPMailer - 如何从“正确发送”

看看我的代码的一部分,然后看看GMail的编辑“源”的屏幕截图隐藏实际的电子邮件等。

配置的一部分(编辑匹配截屏数据)

$config_mail = array(
    'MAIL_FROM'     => '[email protected]', 
    'MAIL_NAME'     => 'Company Name', 
    'MAIL_SMTP_HOST'   => 'smtp.gmail.com', 
    'MAIL_SMTP_PORT'   => 587, 
    'MAIL_SMTP_SECURE'   => 'tls', 
    'MAIL_SMTP_AUTH'   => true, 
    'MAIL_SMTP_USER'   => '[email protected]', 
    'MAIL_SMTP_PASS'   => '*******' 
); 

PHPMailer的的部分

// Add a "Reply-to" address. 
$mail->addReplyTo($form_email, $form_name); 
// Set the From and FromName properties 
$mail->setFrom($form_email, $form_name); 
// Add a "To" address. 
$mail->addAddress($config_mail['MAIL_FROM'], $config_mail['MAIL_NAME']); 

截图(在解释说明跌破发行) gmail edit screenshot

问题的解释 您可以在图像上看到,从不正确,所以我不得不使用$的replyTo,但它仍然似乎是一个问题给我。也许它一定是这样的,因为它使用SMTP从服务器发送,但我仍然想知道为什么它是这样的,是否有可能改变它?

我相信这行:

from: Sender Name <[email protected]> 

应该是这样,而是:

from: Sender Name <[email protected]> 

所以,我错了,或者它必须是这个样子?我试图深入解释我的问题,希望我能得到高质量的答案,因为我真的不明白!

回答

2

无论您尝试使用您使用的任何编程语言来设置Gmail,Gmail都会将发件人强制转换为已通过身份验证的用户。此行为是设计使然。

+0

嗯,好吧,如果是这样的。这是否意味着如果我为我的域名设置了一封电子邮件,例如:[email protected],我将实际得到正确的“from”而不是“smtp from”? – dvLden 2014-09-26 09:24:14

+0

@dvLden,如果您的网域授权设置特定的“from”(与Gmail不同),则应该正常运行。 – 2014-09-26 09:28:15

+0

如果任何一个gmail正在处理您的域名,或者您已经授权个人'来自'地址,它就可以工作。 – Synchro 2014-09-26 09:44:53

1

试试这个:

//Create a new PHPMailer instance 
$mail = new PHPMailer(); 
//Set who the message is to be sent from 
$mail->setFrom('[email protected]', 'First Last'); 
//Set an alternative reply-to address 
$mail->addReplyTo('[email protected]', 'First Last'); 
//Set who the message is to be sent to 
$mail->addAddress('[email protected]', 'John Doe'); 
//Set the subject line 
$mail->Subject = 'PHPMailer mail() test'; 
//Read an HTML message body from an external file, convert referenced images to embedded, 
//convert HTML into a basic plain-text alternative body 
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__)); 
//Replace the plain text body with one created manually 
$mail->AltBody = 'This is a plain-text message body'; 
//Attach an image file 
$mail->addAttachment('images/phpmailer_mini.png'); 

//send the message, check for errors 
if (!$mail->send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
+0

我不需要PHPMailer示例队友 – dvLden 2014-09-26 09:22:57