从本地主机发送电子邮件(Windows) [英] Send email from localhost with gmail(windows)

查看:131
本文介绍了从本地主机发送电子邮件(Windows)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用我的localhost的mail()函数。我有WAMP安装和一个Gmail帐户。我知道SMTP的SMTP是smtp.gmail.com,端口是465.我需要在WAMP中配置,所以我可以使用mail()函数?
谢谢

解决方案

Ayush的答案非常有用,下面略微简化了一下方法

1)下载 PHPMailer

2)提取到php项目中的文件夹,并将其重命名为phpmailer

3)创建gmail-sample.php并粘贴以下代码:

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

// ----------调整这些行--------------------------- ------------
$ mail->用户名=your.username@gmail.com; //您的GMail用户名
$ mail-> Password =your-gmail-password;
$ mail-> AddAddress(friends.email@domain.com); //收件人电子邮件
$ mail-> FromName =你的名字; //可读名称

$ mail-> Subject =主题标题;
$ mail-> Body =这是您要发送给你的朋友的消息。
// -------------------------------------------- ---------------------------

$ mail-> Host =ssl://smtp.gmail .COM; // GMail
$ mail-> Port = 465;
$ mail-> IsSMTP(); //使用SMTP
$ mail-> SMTPAuth = true; //打开SMTP认证
$ mail-> From = $ mail->用户名;
if(!$ mail-> Send())
echoMailer Error:。 $ MAIL-> ERRORINFO;
else
echo已发送消息;
?>

4)从浏览器发送邮件(例如 http://localhost/your-project/gmail-sample.php )。


I want to use the mail() function from my localhost. I have WAMP installed and a Gmail account. I know that the SMTP for Gmail is smtp.gmail.com and the port is 465. What I need to configure in WAMP so I can use the mail() function? Thanks

解决方案

Ayush's answer was very useful, below a slightly simplified approach
1) Download PHPMailer
2) Extract to folder within you php project and rename it to phpmailer
3) Create gmail-sample.php and paste the following code:

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

    // ---------- adjust these lines ---------------------------------------
    $mail->Username = "your.username@gmail.com"; // your GMail user name
    $mail->Password = "your-gmail-password"; 
    $mail->AddAddress("friends.email@domain.com"); // recipients email
    $mail->FromName = "your name"; // readable name

    $mail->Subject = "Subject title";
    $mail->Body    = "Here is the message you want to send to your friend."; 
    //-----------------------------------------------------------------------

    $mail->Host = "ssl://smtp.gmail.com"; // GMail
    $mail->Port = 465;
    $mail->IsSMTP(); // use SMTP
    $mail->SMTPAuth = true; // turn on SMTP authentication
    $mail->From = $mail->Username;
    if(!$mail->Send())
        echo "Mailer Error: " . $mail->ErrorInfo;
    else
        echo "Message has been sent";
    ?>

4) Send mail from Browser (e.g. http://localhost/your-project/gmail-sample.php).

这篇关于从本地主机发送电子邮件(Windows)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆