如何使用XAMPP从PHP发送电子邮件


How to send email from PHP using XAMPP

我想使用GMAIL SMTP使用XAMPP(Windows)附带的库从PHP发送电子邮件。我还想发送附件。

有人会在windows中默认安装XAMPP时发布测试代码吗?

您可以使用PHPMailer在PHP上通过Gmail发送电子邮件。

示例:

require_once('class.phpmailer.php');
$mail             = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPAuth   = true;
$mail->SMTPSecure = "tls";
$mail->Username   = "yourusername@gmail.com";
$mail->Password   = "yourpassword";          
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 587;           
$mail->SetFrom('yourusername@gmail.com', 'Your Name');
$mail->Subject    = "My subject";
$mail->Body    = "My body";
$mail->AddAddress("someone@example.com", "Recipient name");
$mail->Send();