【发布时间】:2011-11-28 14:31:58
【问题描述】:
require_once('phpmailer/class.phpmailer.php');
function smtpmailer($to,$from,$subject,$body) {
define('GUSER', 'xxx'); // Gmail username
define('GPWD', 'xxx'); // Gmail password
printf("list:".$to);
$recipient = array ($to);
global $error;
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
$mail->Host = 'smtp.gmail.com';
$mail->Port = 465;
$mail->Username = GUSER;
$mail->Password = GPWD;
$mail->SetFrom($from, "Bank Negara");
$mail->Subject = $subject;
$mail->Body = $body;
foreach ($recipient as $email){
$mail->AddAddress($email);
}
if(!$mail->Send()) {
$error = 'Mail error: '.$mail->ErrorInfo;
return false;
} else {
$error = 'Message sent!';
return true;
}
}
我正在传递一个以这种格式保存电子邮件地址的字符串:
'email1@yahoo.com','email2@gmail.com'
当我通过这个时
$recipient = array ($to);
我有错误地址无效:但是当我像这样直接传递字符串输出时:
$recipient = array ('email1@yahoo.com','email2@gmail.com');
它工作正常。应该如何将我的 $to String 传递给这个 $recipient 数组。
【问题讨论】:
-
我已从该帖子中删除了您的 gmail 帐户/密码信息。您可能应该立即更改该密码。