我知道我的php表单在godaddy服务器上运行: http://thespanishlanguageacademy.net/los-angeles/learn-spanish-kids-children/kontact.html
请自行测试,将您的电子邮件地址放入其中并发送给您。
我将相同的代码复制到不同的服务器中。这个服务器不是爸爸。我知道php可以在这台服务器上运行,但由于某种原因,这个表单不起作用:
http://hancockcollege.us/kontact.html
这是php代码:
// if the Email_Confirmation field is empty
if(isset($_POST['Email_Confirmation']) && $_POST['Email_Confirmation'] == ''){
// put your email address here scott.langley.ngfa@statefarm.com, slangleys@yahoo.com
$youremail = 'bomandty@gmail.com';
// prepare a "pretty" version of the message
$body .= "Thank You for contacting us! We will get back with you soon.";
$body .= "\n";
$body .= "\n";
foreach ($_POST as $Field=>$Value) {
$body .= "$Field: $Value\n";
$body .= "\n";
}
$CCUser = $_POST['EmailAddress'];
// Use the submitters email if they supplied one
// (and it isn't trying to hack your form).
// Otherwise send from your email address.
if( $_POST['EmailAddress'] && !preg_match( "/[\r\n]/", $_POST['EmailAddress']) ) {
$headers = "From: $_POST[EmailAddress]";
} else {
$headers = "From: $youremail";
}
// finally, send the message
mail($youremail, 'Form request', $body, $headers, $CCUser );
}
// otherwise, let the spammer think that they got their message through
答案 0 :(得分:0)
首先, 使用此标题:
<?php
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
//Fom
$headers .= "From: XXX XXXX XXXXX <xxxx@xxxx.xxx>\r\n";
//Reply
$headers .= "Reply-To: example@example.com\r\n";
//Path
$headers .= "Return-path: example@example.com\r\n";
//CC
$headers .= "Cc: example@example.com\r\n";
//BBC
$headers .= "Bcc: example@example.com,example@example.com\r\n";
?>
二,阅读PHPMailer并查看下一个代码:
试试这个:
<?php
date_default_timezone_set('Etc/UTC');
require '../PHPMailerAutoload.php';
//Create a new PHPMailer instance
$mail = new PHPMailer();
//Tell PHPMailer to use SMTP
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 2;
//Ask for HTML-friendly debug output
$mail->Debugoutput = 'html';
//Set the hostname of the mail server
$mail->Host = "mail.example.com";
//Set the SMTP port number - likely to be 25, 465 or 587
$mail->Port = 25;
//Whether to use SMTP authentication
$mail->SMTPAuth = true;
//Username to use for SMTP authentication
$mail->Username = "yourname@example.com";
//Password to use for SMTP authentication
$mail->Password = "yourpassword";
//Set who the message is to be sent from
$mail->setFrom('from@example.com', 'First Last');
//Set an alternative reply-to address
$mail->addReplyTo('replyto@example.com', 'First Last');
//Set who the message is to be sent to
$mail->addAddress('whoto@example.com', 'John Doe');
//Set the subject line
$mail->Subject = 'PHPMailer SMTP test';
//Read an HTML message body from an external file, convert referenced images to embedded,
//convert HTML into a basic plain-text alternative body
$mail->msgHTML(file_get_contents('contents.html'), dirname(__FILE__));
//Replace the plain text body with one created manually
$mail->AltBody = 'This is a plain-text message body';
//Attach an image file
$mail->addAttachment('images/phpmailer_mini.gif');
//send the message, check for errors
if (!$mail->send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
答案 1 :(得分:-1)
也许您必须在其他服务器上手动初始化SMTP路径,我之前遇到过类似的问题,设置正确的SMTP修复了我的问题。
ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "yourmeail@yourdomain.com");