最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
php 使用身份验证的SMTP发送电子邮件
时间:2022-07-02 10:31:24 编辑:袖梨 来源:一聚教程网
YPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" "http://www.w***3.org/TR/REC-html40/loose.dtd">
这个例子说明如何发送电子邮件使用SMTP身份验证。此特定示例使用Gmail发送。为通过SMTP发送如需Gmail要求的SMTP TLS身份验证。幸运的是,当我们使用梨邮件认证,连接自动TLS的。
这个例子之间的区别,只是在前面的示例使用SMTP是增加以下SMTP参数。
$smtp_params["auth"] = true; $smtp_params["username"] = "[email protected]"; $smtp_params["password"] = "pass";
include('Mail.');
include('Mail/mime.php');
// Constructing the email
$sender = "[email protected]"; // Your email address
$recipient = "Leigh.net>"; // The Recipients name and email address
$subject = "Test Email"; // Subject for the email
$text = 'This is a text message.'; // Text version of the email
$html = 'This is a html message
'; // HTML version of the email
$crlf = "n";
$headers = array(
'From' => $sender,
'Return-Path' => $sender,
'Subject' => $subject
);
// Creating the Mime message
$mime = new Mail_mime($crlf);
// Setting the body of the email
$mime->setTXTBody($text);
$mime->setHTMLBody($html);
// Add an attachment
$file = "Hello World!";
$file_name = "Hello text.txt";
$content_type = "text/plain";
$mime->addAttachment ($file, $content_type, $file_name, 0);
// Set body and headers ready for base mail class
$body = $mime->get();
$headers = $mime->headers($headers);
// SMTP authentication params
$smtp_params["host"] = "smtp.gmail.com";
$smtp_params["port"] = "25";
$smtp_params["auth"] = true;
$smtp_params["username"] = "[email protected]";
$smtp_params["password"] = "pass";
// Sending the email using smtp
$mail =& Mail::factory("smtp", $smtp_params);
$result = $mail->send($recipient, $headers, $body);
if($result === 1)
{
echo("Your message has been sent!");
}
else
{
echo("Your message was not sent: " . $result);
}
?>
相关文章
- 超级机器人大战Y六人一匹一体怎么过 特殊合体关卡攻略 09-16
- 无主之地4解压慢怎么办 解压慢的解决方法 09-16
- 原神隐藏成就无声指令怎么解锁 无声指令成就攻略 09-16
- 超级机器人大战Y斯威特强袭怎么过 高机动歼灭战攻略 09-16
- 无主之地4支线宿醉解药怎么过 宿醉解药支线图文攻略 09-16
- 超级机器人大战Y新世界宣言怎么过 最终决战关卡攻略 09-16