php
2014-04-08 22 views 0 likes 
0

我的ISP已经开始要求SMTP身份验证,我似乎无法弄清楚如何将这些信息添加到我的头文件中。以下是我的代码的简化版本。任何帮助将非常感激。如何发送身份验证的PHP邮件

谢谢。

<?php 
$content = 'Hello'; 
$content .= ' 123'; 

$headers = 'Content-Type: text/html; charset=UTF-8'."\r\n"; 
$headers .= 'From: ABC <[email protected]>'; 

// The four lines below need to be fixed. 
$smtpinfo["host"] = "host.hostingcompany.com"; 
$smtpinfo["port"] = "25"; 
$smtpinfo["auth"] = true; 
$smtpinfo["username"] = "username"; 
$smtpinfo["password"] = "password"; 

$sent = '[email protected]', 'A test email', $content, $headers); 
$sent = '[email protected]', 'A test email', $content, $headers); 
?> 

回答

0

尝试支持像phpMailer(download)

例如SMTP验证的第三方库用法:

require_once('class.phpmailer.php'); 

$mail    = new PHPMailer(); 

$body    = "Your<br>HTML Message"; 

$mail->IsSMTP(); // telling the class to use SMTP 
$mail->Host  = "mail.yourdomain.com"; // SMTP server 
$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 
              // 1 = errors and messages 
              // 2 = messages only 
$mail->SMTPAuth = true;     // enable SMTP authentication 
$mail->Host  = "mail.yourdomain.com"; // sets the SMTP server 
$mail->Port  = 26;     // set the SMTP port for the GMAIL server 
$mail->Username = "[email protected]"; // SMTP account username 
$mail->Password = "yourpassword";  // SMTP account password 

$mail->SetFrom('[email protected]', 'First Last'); 

$mail->AddReplyTo("[email protected]","First Last"); 

$mail->Subject = "PHPMailer Test Subject via smtp, basic with authentication"; 

$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test 

$mail->MsgHTML($body); 

$address = "[email protected]"; 
$mail->AddAddress($address, "John Doe"); 

if(!$mail->Send()) { 
    echo "Mailer Error: " . $mail->ErrorInfo; 
} else { 
    echo "Message sent!"; 
} 
+0

这是唯一的方法吗?可以在不添加phpmailer的情况下完成吗?谢谢。 – user3495744

+0

这是另一种方式... http://email.about.com/od/emailprogrammingtips/qt/PHP_Email_SMTP_Authentication.htm – Latheesan

相关问题