佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1037|回复: 4

php 前辈帮帮忙 - php 发送 email

[复制链接]
发表于 19-1-2007 04:10 PM | 显示全部楼层 |阅读模式
我的运行系统是 xp + apache + mysql
我只是localhost 来 test 我的php
我的error 是

Warning:  mail() [function.mail]:Failed to connect to mailserver at "localhost" port 25, verify your"SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Apache2\htdocs\vp\test\filename.php on line 22
Cannot Send Email


我想要用php来 自动发送 email
请问要又如何设我的 file.php 和 php.ini ??
要如何设定smtp??
谢谢


file.php

<?php

$to="kimokek@yahoo.com";

$subject="Test";

$header="from: your name <your email>";

$message="Hello \r\n";
$message.="This is test\r\n";
$message.="Test again ";

$sentmail = mail($to,$subject,$message,$header);


if($sentmail){
echo "Email Has Been Sent .";
}
else {
echo "Cannot Send Email ";
}


?>



php.ini

[mail function]
; For Win32 only.
SMTP = localhost(要改吗?)
smtp_port = 25

; For Win32 only.
sendmail_from = kimokek@yahoo.com(不懂要放什么?)

[ 本帖最后由 kimokek 于 19-1-2007 04:12 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

发表于 19-1-2007 09:42 PM | 显示全部楼层
SMTP issue, if you 're using offline localhost.
change the smtp - something like brabra.domainbrabra.com or a real life example : smtp.streamyx.com..well just a sample.

or

refer to this url: http://www.sitepoint.com/article/advanced-email-php

And

There's pretty much stuff like "PHP sendmail tutorial" if you just googling through..Piece of cake..hope it helps.

P/S: message me if anything you would like me to help.



Cheers,
Calverstine
回复

使用道具 举报

发表于 20-1-2007 03:49 AM | 显示全部楼层
原帖由 Kal1983 于 19-1-2007 09:42 PM 发表
SMTP issue, if you 're using offline localhost.
change the smtp - something like brabra.domainbrabra.com or a real life example : smtp.streamyx.com..well just a sample.

or

refer to this ur ...


最近streamyx 的 smtp 好像request authentication 了。 在outlook express 要设定好才能sendmail.
php.ini 这只设定smtp 好像也发不出电邮了。不是很肯定,没去test,有没有人式过?
回复

使用道具 举报

发表于 20-1-2007 11:04 AM | 显示全部楼层
你必须需要有SMTP 服务器的户口

[mail function]
; For Win32 only.
SMTP = smtp.tm.net << 放你的smtp服务器的网址
smtp_port = 25     << 放你的smtp服务器的端口

; For Win32 only.
sendmail_from = xxx@tm.net.my <<放你的Email地址。


这种方式不支持ESMTP认证的,所以TM主机应该不适合用。

推荐使用一个支持认证嘚函数:

转载关于BMforum的邮件程序片断:
代码由Bmforum.com所有
/*
BMForum Datium! Bulletin Board Systems
Version : Datium!

This is a freeware, but don't change the copyright infomation.
A SourceForge Project - GNU Licence project.
Web Site: http://www.bmforum.com
Copyright (C) Bluview Technology
*/

//  通过 BMForum ESMTP 模块发信
        $mailcfg['server'] = 'localhost';        //  SMTP 服务器
        $mailcfg['port'] = '25';        //  SMTP 端口               
        $mailcfg['auth'] = 0;                // 是否需要登录验证, 1=是, 0=否
        $mailcfg['from'] = 'root@localhost';        
// 发信人地址 (如果需要验证,必须为本服务器地址)
        $mailcfg['auth_username'] = '';                //  邮箱用户名
        $mailcfg['auth_password'] = '';                //  邮箱密码


/****************下列无需更动************************/

        $fp = fsockopen($mailcfg['server'], $mailcfg['port'], &$errno, &$errstr, 30);

        $from = $mailcfg['from'];
        if($mailcfg['auth']) {
                fputs($fp, "EHLO bmmailer\r\n");
                fputs($fp, "AUTH LOGIN\r\n");
                fputs($fp, base64_encode($mailcfg['auth_username'])." \r\n");
                fputs($fp, base64_encode($mailcfg['auth_password'])." \r\n");
        } else {
                fputs($fp, "HELO bmmailer\r\n");
        }
        fputs($fp, "MAIL FROM: $from\r\n");
        foreach(explode(',', $to) as $touser) {
                $touser = trim($touser);
                if($touser) {
                        fputs($fp, "RCPT TO: $touser\r\n");
                }
        }
        fputs($fp, "DATA\r\n");
        $tosend = $headers ? $headers."\r\n" : "From: $from\r\n";
        $tosend .= "To: BMForum Members\r\n";
        $tosend .= 'Subject: '.$subject."\r\n\r\n$message\r\n.\r\n";
        fputs($fp, $tosend);
        fputs($fp, "QUIT\r\n");
        $response = fgets($fp,10000);
        $temp = fread($fp, 10000);
        $response .= fread($fp, 10000);
        fclose($fp);
回复

使用道具 举报

发表于 22-1-2007 03:46 PM | 显示全部楼层
如果你直接放上online server,你的这个问题就不存在了。。。
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 27-8-2025 01:46 PM , Processed in 0.106411 second(s), 21 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表