1

我在 php 中使用电子邮件时遇到问题,我想给自己发邮件(只是为了测试),我想使用此功能,以便用户可以从网站向我发送他们的反馈。

我在 php.ini 中启用了 openssl,我在 localhost 和 win7 上使用 wamp server 2.0,请帮助我,我是 php 新手!这是代码: -

<?php
require('PHPMailer/class.phpmailer.php');
$mail = new PHPMailer;

$mail->IsSMTP();                                      // Set mailer to use SMTP
$mail->SMTPDebug = 1;
$mail->Port = 587;
$mail->Host = 'mail.gmail.com';  // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'myid@gmail.com';                            // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                   // Enable encryption, 'ssl' also accepted

$mail->From = 'myid@gmail.com';
$mail->FromName = 'AshiMailer';
$mail->AddAddress('myid.sbit@gmail.com', 'Josh Adams');  // Add a recipient
$mail->AddAddress('myid@gmail.com');               // Name is optional
$mail->AddReplyTo('myid@gmail.com', 'Information');
//$mail->AddCC('cc@example.com');
//$mail->AddBCC('bcc@example.com');

$mail->WordWrap = 50;                                 // Set word wrap to 50 characters
//$mail->AddAttachment('/var/tmp/file.tar.gz');         // Add attachments
//$mail->AddAttachment('/tmp/image.jpg', 'new.jpg');    // Optional name
$mail->IsHTML(true);                                  // Set email format to HTML

$mail->Subject = 'Here is the subject';
$mail->Body    = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}

echo 'Message has been sent';

?>
4

1 回答 1

0

使用这些设置

$mail->SMTPSecure = 'tls';
$mail->Host = 'smtp.gmail.com';
于 2013-08-08T13:48:24.297 回答