//这个php通过自定义smtp服务器将电子邮件发送到指定的电子邮件地址。连接两个单独的字符串变量后得到的电子邮件地址。 //问题在这里:例如,对于johnny@mail.com,johnny是$ username变量,@ mail.com是$ mailprovider变量。如果我回显$ address变量,我得到johnny@mail.com,但服务器不发送邮件。
<?php
require_once "Mail.php";
$host = "smtp.domain.com";
$username = "user@domain.com";
$password = "validpass";
if(isset($_POST['submit'])) {
$address = $username.$mailprovider;
$emailTo = $address;
$body = "Name: $name \n\nMessage: $message";
$headers = array ('From' => 'user@domain.com', 'To' => $emailTo, 'Subject' => 'test');
$smtp = Mail::factory('smtp', array('host'=>$host, 'auth'=>true, 'username'=>$username, 'password'=>$password));
$mail = $smtp->send($emailTo, $headers, $body);
if(PEAR::isError ($mail)){
echo("<p>. $mail->getMessage().</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
$emailSent = true;
}
?>