2014-09-26 25 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