我一直在尝试利用 jquery contactable 插件(在 google 上找到!)中的 mail.php 文件在我的网站上使用。尽管提供的脚本相当简单,但我在将其与主机的 SMTP 要求集成时遇到了问题。这是没有 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] /cdn-cgi/l/email-protection', $subject, $contactMessage, $headers) ) ? "success" : "failure" ;
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
我尝试使用谷歌的建议并尝试了几个小时。这是基于我迄今为止对 php 的零理解的最新版本。 -__-(基于此:http://blog.geek4support.com/php-mail-script-with-smtp-authentication-how-to-send-mails-by-php-mail-script-using-smtp-authentication/ 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] /cdn-cgi/l/email-protection";
$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] /cdn-cgi/l/email-protection', $subject, $contactMessage, $headers)) ? "success": "failure";
$output = json_encode(array("response" => $response));
header('content-type: application/json; charset=utf-8');
echo($output);
?>
我实际上遇到了一些问题。我的主机不支持 PHPMailer :-(。仅支持 SMTP 的 PearMail。他们建议调整上面列出的代码并将我现有的代码合并到其中。确切地说,在网上发布此内容之前我一直在尝试做的事情。回到广场1、有什么想法吗?
意见、建议,任何事情都将不胜感激! :-)