将Sendmail更改为Pear Mail

时间:2014-12-09 19:24:28

标签: php email smtp pear

我一直在尝试使用带有SMTP的Pear Mail,因此我更改了以下代码。但是,邮件没有发送,当我提交show" $ headers必须是一个数组"。我的代码在哪里出错?

$today = date("Y-m-d H:i:s");
$data = $ip . ' ' . $today . PHP_EOL;

require_once "Mail.php";
$host = "146.168.8.237";
$port = "25";
$subject = "A Card from {$ayname}";
$smtp = Mail::factory('smtp', array ('host' => $host, 'port' => $port,'auth' => false));

$headers = array ('From' => $aymail,'To' => $recipent,'Subject' => $subject);
$headers = "From: {$ayname}<{$aymail}>\r\n" . "MIME-Version: 1.0\r\n" . "Content-type: text/html;       charset=utf-8";
$recipients = explode(",", $arsemail);
$amsg11=addslashes($amsg);
foreach($recipients as $recipient){
mysql_query('INSERT INTO `contact` (`id`,`ip_address`,`recipient_email`,`your_email`, `message`,`date`) VALUES (NULL,"'.$ip.'","'.$recipient.'","'.$aymail.'","'.$amsg11.'","'.$today.'")');

$mail = $smtp->send($recipient , $subject , $mailbody, $headers); 

1 个答案:

答案 0 :(得分:0)

你有以下代码,我认为错误必须在第二个简单地删除第二行更好地删除或评论第二行

$headers = array ('From' => $aymail,'To' => $recipent,'Subject' => $subject);
$headers = "From: {$ayname}<{$aymail}>\r\n" . "MIME-Version: 1.0\r\n" ....
$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject);

  $message = new Mail_mime($crlf);

    $message->setTXTBody($body);
    $message->setHTMLBody($body_html);
    $body = $message->get();
    $headers = $message->headers($headers);
    $smtp = Mail::factory('smtp',
    array ('host' => $host,
   'auth' => true,
   'port' => xxx,
  'username' => $username,
  'password' => $password));

    $mail = $smtp->send($to, $headers, $body);

完整的工作功能不要忘记包含邮件文件

&#13;
&#13;
function doEmail($to, $message $subject, $name){



$from = "Administrator <admin@xyz.com>";
$reply_email = "bounce@xyz.com";
$to = "$name <$to>";
$subject = $subject;

$body = strip_tags($m);
$body_html = $m;
$crlf = "\n";
$host = "localhost";
$username = "";
$password = "";
$headers = array ('From' => $from,
  'To' => $to,
  'Subject' => $subject,
  'Reply-To' => $reply_email,
  'Return-path' => $reply_email,
  'Content-Type' => "text/html; charset=utf-8");
  
  $message = new Mail_mime($crlf);

    $message->setTXTBody($body);
    $message->setHTMLBody($body_html);
    $body = $message->get();
    $headers = $message->headers($headers);  
  
$smtp = Mail::factory('smtp',
  array ('host' => $host,
    'auth' => false,
    'username' => '',
    'password' => ''));

		$mail = $smtp->send($to, $headers, $body);

		if (PEAR::isError($mail)) {
		
		} else {
		
		}

}
&#13;
&#13;
&#13;