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;
}
}
我传递其持有这种格式的电子邮件地址的字符串:PHP梅勒您必须至少提供一个电子邮件地址
'[email protected]','[email protected]'
当我路过这个
$recipient = array ($to);
我有错误无效的地址:但是当我直接传递字符串输出如下:
$recipient = array ('[email protected]','[email protected]');
它工作正常。如何将我的$传递给这个$收件人数组。
我已经删除您的gmail帐户/密码信息从这个职位。你应该马上改变这个密码。 –