English 中文(简体)
如何显示或保存电子邮件, 而不是将邮件实际发送到本地主机?
原标题:How to display or save emails instead of actual sending them on localhost?

I m working on a php project where all emails are sent via the mail() function. That s quite a problem to prepare and test those emails because mail() function fails on the localhost and I should constantly rewrite my code to print out the email before sending, check it and asume that on server it would be sent ok.

Is there a way to somehow manage such situations? I will be very happy if there is a way to save the messages on hard disk or send them only to the one specific email address, not to the real recipients, without or with slight modification of the code. Some useful software or advices are so appreciated.

谢谢!

P. S. 当地主机我使用WAMP软件包作为网络服务器。

最佳回答

http://www.toolheap.com/test-mail-server-tool/" rel="noreferrer">http://www.toolheap.com/test-mail-server-tool/

Windows 测试邮件服务器工具真棒! 每次您在本地主机上发送电子邮件时, 都会在您最喜爱的电子邮件阅读器( 即展望、 邮箱等) 中发布电子邮件 。

我用它来测试所有WAMP的网络应用程序!

无需更改服务器, 只需下载和安装, 然后发送电子邮件, 并在操作中看到它 。

- 哦,这是自由的!

问题回答

Here is the solution I found to get around this problem. 1. Create the sendmail.php file somewhere in the wamp dir, e.g. d:wampappssendmail.php. Here is it s source:

/* Path where emails will be stored */
define( DST ,  d:/wamp/tmp/sendmail/ );
/* Extract the message from the stdin */
$message =   ;
while(($line = fgets(STDIN)) !== false) {
    $message .= $line;
}
/* Save message to file */
file_put_contents(DST.date( Y-m-d_H-i-s_ ).md5($message). .eml , $message);

2. 在 < 坚固> php. ini < /坚固 > 中取消和编辑 < 坚固> endsendmail_ path < /坚固 > 参数。

sendmail_path = "D:wampinphpphp5.3.5php.exe D:wampappssendmail.php"

通过邮件() 函数发送的所有信件将被记录并存储在指定的目录中。

安装 < a href=> " "http://www.lastcraft.com/ fakemail.php" rel=“nofollow” > fakemail 。 它作为本地 SMTP 服务器, 并在文件夹中保存所有邮件 。

您可以将 mail () 函数, 例如 :

function my_send_mail(/*...*/) {
   if (is_localhost()) {
      // just save the mail to text.
   } else {
      // call mail() and send mail
   }
}

使用此函数代替直接使用邮件 () 。





相关问题
Angle brackets in php

I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out. The following is the code that doesn t seem to work. while(...) { $msg .= "<...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka s version of authlogic_openid which I found on Github since pelle s original addition of the feature seemed to cause issues. http://...

Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

How to track an email in Java?

How I can track an email? I m using java on the server side for sending emails. I want to track whether it is delivered , opened, etc... How I can do that ?

Web Link in a mail is not rendering as link in yahoo

string from = "abc@gmail.com"; string to = "xyz@gmail.com,xyz@yahoo.co.in"; string password="abcxyz"; MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

How to create an email mailing list

Im creating a coming soon page for a website im developing, and im adding an option for the user to enter their email address so we can email them when the site is up. How do I do this?

CCNet email does not include MSBuild results

We re using CCNet 1.4.4.83 but when an MSBuild task fails, we don t get the MSBuild results (i.e. missing file or whatever reason the compile failed) in the email notification. I do see the build ...

热门标签