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

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

问题描述

我想使用本地主机的 mail() 函数.我安装了 WAMP 和一个 Gmail 帐户.我知道 Gmail 的 SMTP 是 smtp.gmail.com,端口是 465.我需要在 WAMP 中配置什么才能使用 mail() 函数?谢谢

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 的回答非常有用,下面是一个稍微简化的方法
1) 下载PHPMailer
2) 解压到 php 项目中的文件夹并将其重命名为 phpmailer
3) 创建 gmail-sample.php 并粘贴以下代码:

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) 从浏览器发送邮件(例如 http://localhost/your-project/gmail-sample.php).

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

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

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