我一直在尝试利用jQuery联系插件(google上的!)在我的网站上使用mail.php文件。虽然提供的脚本非常简单,但我遇到了将其与Host的SMTP要求集成的问题。这里是没有SMTP认证的原始脚本:Mail.php&Smtp身份验证问题
<?php
// Assign contact info
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
// Set headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br />
<strong>E-mail:</strong> $emailAddr <br />
<strong>Issue:</strong> $issue </p>
<p><strong>Message:</strong> $comment </p>
<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br />
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";
// Send and check the message status
$response = (mail('[email protected]', $subject, $contactMessage, $headers)) ? "success" : "failure" ;
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
我试过使用来自Google的建议,并使用它几个小时来玩。这是基于我迄今为止对PHP的无知的最新版本。 -__-(在此基础上:http://blog.geek4support.com/php-mail-script-with-smtp-authentication-how-to-send-mails-by-php-mail-script-using-smtp-authetication/)
<?php
require_once "Mail.php";
// Assign contact info
$name = stripcslashes($_POST['name']);
$emailAddr = stripcslashes($_POST['email']);
$issue = stripcslashes($_POST['issue']);
$comment = stripcslashes($_POST['message']);
$subject = stripcslashes($_POST['subject']);
$host = "mail.mywebsite.com";
$username = "[email protected]";
$password = "mymailpassword";
// Set headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Format message
$contactMessage =
"<div>
<p><strong>Name:</strong> $name <br />
<strong>E-mail:</strong> $emailAddr <br />
<strong>Issue:</strong> $issue </p>
<p><strong>Message:</strong> $comment </p>
<p><strong>Sending IP:</strong> $_SERVER[REMOTE_ADDR]<br />
<strong>Sent via:</strong> $_SERVER[HTTP_HOST]</p>
</div>";
$smtp = Mail::factory('smtp',
array ('host' => $host,
'auth' => true,
'username' => $username,
'password' => $password));
$response = ($smtp->send('[email protected]', $subject, $contactMessage, $headers)) ? "success": "failure";
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
其实我已经遇到了一点问题。我的主机不支持PHPMailer :-(。只有PearMail和SMTP,他们建议调整上面列出的代码,并将其与现有的代码合并在一起。 1,任何想法?
意见,建议,什么都将是非常感谢!:-)
mail.php是什么,我们包括在行首。 – TechCare99 2013-07-24 18:22:41