简体   繁体   English

如何使用localhost项目中的WAMP在PHP中发送电子邮件?

[英]How to send emails in PHP using WAMP from localhost project?

I have a project folder say myproject in wamp/www folder. 我在wamp / www文件夹中有一个项目文件夹,说myproject。 I have latest version of wamp installed on my system. 我的系统上安装了最新版本的wamp。 I have abc.php file in myproject folder from which I am trying to send email. 我试图从中发送电子邮件的myproject文件夹中有abc.php文件。 When I am running my project from localhost (localhost/myproject/abc.php), I am getting following error: 当我从本地主机(localhost / myproject / abc.php)运行项目时,出现以下错误:

Warning: mail(): Failed to connect to mailserver at "mail.google.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

How should I resolve this warning? 我应该如何解决此警告? Right not I don't have any mail server running on my system and I also don't want to run if for now. 是的,不是,我的系统上没有运行任何邮件服务器,如果现在也不想运行。 When I will host this site to any server, then I will use their mail server to configure my smtp. 当我将该站点托管到任何服务器时,我将使用他们的邮件服务器来配置我的smtp。 But for now on localhost, how should I make myself able to send emails. 但是目前在localhost上,我应该如何使自己能够发送电子邮件。 I am trying to use ini_set method to do the job. 我正在尝试使用ini_set方法来完成这项工作。

            $to=$_POST["email"];
            $subject="Hi Message";
            $msg="mail contents";               
            $headers="From: no-reply@mydomainname.com";

            //ini_set("SMTP","mail.google.com");
            //ini_set("smtp_port","25");
        if(mail($to, $subject, $msg, $headers)) 
            {
                $msg="Email sent successfully.";
            echo $msg;
            }
            else
            {
                $msg="Email sending error";
                echo $msg;
            }

SMTP class is the best option to send mail in PHP. SMTP类是使用PHP发送邮件的最佳选择。 Here is the link 链接在这里

http://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.smtp.php?r=170 http://code.google.com/a/apache-extras.org/p/phpmailer/source/browse/trunk/class.smtp.php?r=170

我本人是PHPMailer的忠实粉丝。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM