电子邮件php脚本赢得';不要发电子邮件

电子邮件php脚本赢得';不要发电子邮件,php,html,email,html-email,Php,Html,Email,Html Email,我很难让邮件php脚本正常工作,我可能不明白为什么,因为我已经在互联网上找到了它,但我没有找到正确的解决方案(这是一种新的解决方案) 如果我运行脚本,它总是进入最后一个,如果出现问题,请重试 以下是脚本: <?php $siteOwnersEmail = 'test@gmail.be'; if($_POST) { $name = trim(stripslashes($_POST['contactName'])); $email = trim(stripslashes($_POS

我很难让邮件php脚本正常工作,我可能不明白为什么,因为我已经在互联网上找到了它,但我没有找到正确的解决方案(这是一种新的解决方案)

如果我运行脚本,它总是进入最后一个,如果出现问题,请重试

以下是脚本:

<?php


 $siteOwnersEmail = 'test@gmail.be';


if($_POST) {

$name = trim(stripslashes($_POST['contactName']));
$email = trim(stripslashes($_POST['contactEmail']));
$subject = trim(stripslashes($_POST['contactSubject']));
$contact_message = trim(stripslashes($_POST['contactMessage']));

// Check Name
if (strlen($name) < 2) {
    $error['name'] = "Please enter your name.";
}
// Check Email
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
    $error['email'] = "Please enter a valid email address.";
}
// Check Message
if (strlen($contact_message) < 15) {
    $error['message'] = "Please enter your message. It should have at least 15 characters.";
}
// Subject
if ($subject == '') { $subject = "Contact Form Submission"; }


// Set Message
$message .= "Email from: " . $name . "<br />";
$message .= "Email address: " . $email . "<br />";
$message .= "Message: <br />";
$message .= $contact_message;
$message .= "<br /> ----- <br /> This email was sent from your site's contact form. <br />";

// Set From: header
$from =  $name . " <" . $email . ">";

// Email Headers
$headers = "From: " . $from . "\r\n";
$headers .= "Reply-To: ". $email . "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


 if (isset($error)) {

    $response = (isset($error['name'])) ? $error['name'] . "<br /> \n" : null;
    $response .= (isset($error['email'])) ? $error['email'] . "<br /> \n" : null;
    $response .= (isset($error['message'])) ? $error['message'] . "<br />" : null;

    echo $response;


} # end if - there was a validation error
else {


  ini_set("sendmail_from", $siteOwnersEmail); // for windows server
  $mail = mail($siteOwnersEmail, $subject, $message, $headers);

    if ($mail) { echo "OK"; }
  else { echo "Something went wrong. Please try again."; }

} # end if - no validation error

}

}

?>

使用此代码发送邮件,使其正常工作

    <?php
$malil = 'example@example.com';
$to = $malil;

$subject = "Your order has been placed.";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=ISO-8859-1' . "\r\n";   

$headers .= "From: example@example.com" . "\r\n" ;
/* $headers .= "Cc:reservations@bookingsmaker.com,bookingsmakerdotcom@gmail.com,bookingsmakerworld@gmail.com "."\r\n";
*/
$headers .="Cc:example@example.com,example@example.in";

////////////////***********Html format*****************//////////////////
$htmlContent = 'Content';

$result=mail($to,$subject,$htmlContent,$headers);
  if($result){
      echo 'mail Send';
  }else{
      echo 'Mail not send';
  }
  ?>

您能否提供一些关于返回的错误的上下文?
    <?php
$malil = 'example@example.com';
$to = $malil;

$subject = "Your order has been placed.";

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=ISO-8859-1' . "\r\n";   

$headers .= "From: example@example.com" . "\r\n" ;
/* $headers .= "Cc:reservations@bookingsmaker.com,bookingsmakerdotcom@gmail.com,bookingsmakerworld@gmail.com "."\r\n";
*/
$headers .="Cc:example@example.com,example@example.in";

////////////////***********Html format*****************//////////////////
$htmlContent = 'Content';

$result=mail($to,$subject,$htmlContent,$headers);
  if($result){
      echo 'mail Send';
  }else{
      echo 'Mail not send';
  }
  ?>