PHP PEAR郵件問題
echo "start"; $n = $_POST['txtName']; $e = $_POST['txtEmail']; $t = 'Kenny <[email protected]>'; $f = 'Kenny <[email protected]>'; $s = 'CPA TEST'; $b = "name: $n email: $e"; include("mail.php"); echo "after include"; /* mail setup recipients, subject etc */ $recipients = $t; $headers["From"] = $f; $headers["To"] = $t; $headers["Subject"] = $s; $mailmsg = $b; /* SMTP server name, port, user/passwd */ $smtpinfo["host"] = "my_smtp_host"; $smtpinfo["port"] = "25"; $smtpinfo["auth"] = true; $smtpinfo["username"] = "my_email"; $smtpinfo["password"] = "my_password"; echo "before object"; /* Create the mail object using the Mail::factory method */ $mail_object =& Mail::factory("smtp", $smtpinfo); echo "before send"; /* Ok send mail */ $send = $mail_object->send($recipients, $headers, $mailmsg); echo "after send"; if (PEAR::isError($send)) { print($send->getMessage());}else{print "end";} echo "done";
嘗試這樣做,以確保您的郵件正常工作:
<?php require_once "Mail.php"; $from = "Sandra Sender <[email protected]>"; $to = "Ramona Recipient <[email protected]>"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; $host = "mail.example.com"; $username = "smtp_username"; $password = "smtp_password"; $headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject); $smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password)); $mail = $smtp->send($to, $headers, $body); if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>"); } else { echo("<p>Message successfully sent!</p>"); } ?>
如果這不行,那麼您將需要檢查您的PHP配置.
有關詳細資訊,請參閱ofollow,noindex" target="_blank">http://php.net/manual/en/function.mail.php .
程式碼日誌版權宣告:
翻譯自:http://stackoverflow.com/questions/2284468/problem-with-php-pear-mail