我正在使用代码来查找迟到的个人并向他们发送电子邮件。我也找到那些根本没有来过的人,也给他们发邮件。但是,它不起作用。我正确地获取了名称和电子邮件,但$ mail对象为空,我不明白为什么。
这是我的代码:
mail_sender.php(这就是我所说的发送消息)
<?php
function custom_mail($name, $surname, $email, $message, $subject){
//$mail->SMTPDebug = 3; // Enable verbose debug output
require './PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer();
global $mail;
var_dump($mail);
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com;'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '****'; // SMTP username
$mail->Password = '****'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = ****; // TCP port to connect to
$mail->From = '****';
$mail->FromName = '****';
$mail->addAddress($email, $name." ".$surname); // Add a recipient
$mail->addCC('****');
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $subject;
$mail->Body = ucwords($name).' '.ucwords($surname).'! <br />'.$message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//
if(!$mail->send()) {
echo 'email -> '.$email.' name -> '.$name.' surname -> '.$surname.'<br />';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
else {
$mail->ClearAllRecipients(); //clears the list of recipients to avoid other people from getting this email
}
}
?>
有您在您的'mail_sender.php' – 2015-04-02 09:53:24
页面'phpmailer'类是我已经列入它。但是我在错误的地方打电话。我现在刚刚发现了这个错误。感谢您的快速回复,虽然 – 2015-04-02 09:55:57