简体   繁体   English

无法在Wamp服务器上使用php发送电子邮件

[英]unable to send email using php on wamp server

Below is my email code written in php,program works fine but i am unable send mail to gmail. 以下是我用php编写的电子邮件代码,程序工作正常,但我无法将邮件发送到gmail。 am running my code on wamp server(web server) and am using hmail server(mail server) and squirrel mail(web mail interface) 在wamp服务器(Web服务器)上运行我的代码,并在使用hmail服务器(邮件服务器)和松鼠邮件(网络邮件界面)

<?php
$to = 'xyz@local.com';
$subject = 'Customer_Details Report';
$msg="php mail";


$result=mail($to, $subject, $msg);
if($result)
{
echo 'your email has been sent';
}
else
{
echo'email not sent';
}
?>

Here is how I got hMailer to work with my WAMPServer's PHP 这是让hMailer与WAMPServer的PHP一起工作的方式

First setup your hmailer server. 首先设置您的hmailer服务器。

  1. Create a domain, lets call it testmail.net 创建一个域,命名为testmail.net
  2. Create an account that has no password attached to it, lets say nopwd@testmail.net 创建一个没有密码的帐户,例如nopwd@testmail.net
  3. Create an account that is set up as a Catch-all lets say postmaster@testmail.net. 创建一个设置为“全部捕获”的帐户,例如postmaster@testmail.net。 Using this you dont have to create an account for every user you want to send mail to and then login as that user, all mail comes to this account. 使用此方法,您不必为要向其发送邮件的每个用户创建一个帐户,然后以该用户身份登录,所有邮件都将发送到该帐户。

Now add your mail server domain name to the HOSTS file 现在,将您的邮件服务器域名添加到HOSTS文件中

Edit c:\\windows\\system32\\drivers\\etc\\hosts and add a line like this 编辑c:\\ windows \\ system32 \\ drivers \\ etc \\ hosts并添加这样的一行

127.0.0.1  testmail.net

If you are running the mail server on another PC use the IP of the other PC instead of 127.0.0.1 如果您在另一台PC上运行邮件服务器,请使用另一台PC的IP而不是127.0.0.1

Change the php.ini file ( use the wampmanager icon menus to make sure you are editing the correct php.ini ) 更改php.ini文件(使用wampmanager图标菜单确保您编辑的是正确的php.ini)

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = mail.testmail.net
; http://php.net/smtp-port
; assuming you are using the standard port number, change if you used something else.
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from = nopwd@testmail.net

Now just make sure that you also use the from address when you send mail as the hmailer will want this or it will probably reject the email. 现在只需确保在发送邮件时也使用发件人地址,因为hmailer会希望这样做,否则它可能会拒绝该电子邮件。

$to = 'xyz@testmail.net';
$subject = 'Customer_Details Report';
$msg="php mail";
$headers = 'From: nopwd@testmail.net' . "\r\n"    

$result=mail($to, $subject, $msg, $headers);

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

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