略微加速

PHP官方手册 - 互联网笔记

PHP - Manual: Mail

2024-11-12

add a noteadd a note

User Contributed Notes 5 notes

up
3
pouletfou at gmail dot com
12 years ago
I use this script to test webapps using mail with this little php script saved as /usr/sbin/sendmail :

#!/usr/bin/php
<?php
   
//====================================================
    // Program : Fake send mail
    // Author : pouletfou at gmail
    // Description : save this file as /usr/sbin/sendmail
    //  and you can test your PHP applications using mail
    //  by looking at the /tmp/fakesendmail.log files.
    //====================================================

   
define('LOGFILE','/tmp/fakesendmail.log');

   
$log = fopen (LOGFILE,'a+');

   
fwrite($log,"\n".implode(' ',$argv).
    
" called on : ".date('Y-m-d H:i:s')."\n");

   
fwrite($log,file_get_contents("php://stdin"));
   
fwrite($log,
"\n===========================================================\n");
   
fclose($log);

?>
up
2
Some guy
13 years ago
Under windows there is a bug in php/mail

See here: http://bugs.php.net/bug.php?id=28038

this results in you being unable to send 'From: Full Name <me@domain.com>'

Workaround is:

Set the following before calling the mail function:

ini_set('sendmail_from', 'me@domain.com);
up
-24
burkestar at gmail dot com
13 years ago
The workaround mentioned above only works with IIS 5 assuming you've configured the Virtual SMTP Server to accept relays. 

In IIS console, right-click SMTP Virtual Server and choose "Properties". On "Access" tab, click "Relay..." button and make sure "All except the list below" is selected.

Warning: This is just a quick fix which exposes a security risk because allowing your SMTP server to be a relay with anonymous access could make your computer susceptible to becoming a spam zombie.  You should properly add your computer's IP address to the list and choose "Only the list below" instead to lock it down.
up
-45
Ashlin
13 years ago
2 points have to be set :

<?php
ini_set
("SMTP","smtp.example.com" );
ini_set('sendmail_from', 'user@example.com');
?>

or set them in the php.ini file

By doing this, i have fixed definetly this problem :-)
up
-56
dev at realynospamspcweb dot nl
13 years ago
@Crusiatus Black
23-May-2008 05:00

Code below works without errors
<?php

$Name
= "Da Duder"; //senders name
$email = "email@adress.com"; //senders e-mail adress
$recipient = "PersonWhoGetsIt@emailadress.com"; //recipient
$mail_body = "The text for the mail..."; //mail body
$subject = "Subject for reviever"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields

mail($recipient, $subject, $mail_body, $header); //mail command :)
?>

官方地址:https://www.php.net/manual/en/book.mail.php

北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3