-5

我知道我的 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
4

2 回答 2

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!";
}
?>
于 2013-10-30T23:28:18.120 回答
-1

也许您必须在另一台服务器中手动初始化 SMTP 路径,我之前遇到过类似的问题,设置正确的 SMTP 解决了我的问题。

ini_set("SMTP", "aspmx.l.google.com");
ini_set("sendmail_from", "yourmeail@yourdomain.com");
于 2013-10-30T23:25:29.507 回答