<table cellspacing="0" cellpadding="0"><tr><td class="t_f" id="postmessage_19276"> PHPer 多数使用 mail 函数来发送邮件,但我们可以使用其他的 SMTP 服务器来发送,这里推荐使用 PEAR’s mail package 来发送邮件。 <div class="blockcode"> <div id="code_KcC"><ol> <li>$subject = "This mail is sent from SMTP.";</li> <li>$mail_body = "This is the body of the mail which is sent using SMTP.";</li> <li>$from = "From: From Name <fromaddress@xpertdeveloper.com>"; </li> <li>$to = "To: To Name <toaddress@xpertdeveloper.com>"; </li> <li>$receiver = "toaddress@xpertdeveloper.com"; </li> <li> </li> <li>// Setting up the headers</li> <li>$headers["From"] = $from; </li> <li>$headers["To"] = $to; </li> <li>$headers["Subject"] = $subject; </li> <li>$headers["Reply-To"] = "reply@address.com"; </li> <li>$headers["Content-Type"] = "text/plain; charset=ISO-2022-JP"; </li> <li>$headers["Return-path"] = "returnpath@address.com"; </li> <li> </li> <li>// Setting up the SMTP setting</li> <li>$smtp_info["host"] = "smtp.server.com"; </li> <li>$smtp_info["port"] = "25"; </li> <li>$smtp_info["auth"] = true; </li> <li>$smtp_info["username"] = "smtp_user"; </li> <li>$smtp_info["password"] = "smtp_password"; </li> <li> </li> <li>// Creating the PEAR mail object :</li> <li>$mail_obj =& Mail::factory("smtp", $smtp_info); </li> <li> </li> <li>// Sending the mail now</li> <li>$mail_sent = $mail_obj->send($receiver, $headers, $mail_body); </li> <li> </li> <li>// If any error the see for that here:</li> <li>if (PEAR::isError($mail_sent)) { print($mail_sent->getMessage());}</li> </ol></div> <em onclick="copycode($('code_KcC'));">复制代码</em> </div> </td></tr></table> <div id="comment_19276" class="cm"> </div> <div id="post_rate_div_19276"></div> <br><br>