Php没有发送邮件到''密件抄送'和'到'

时间:2015-06-09 10:15:54

标签: php html email

我的查询表格工作正常,但现在只发送电子邮件至Cc电子邮件ID

<?php
if($_REQUEST["name"])
 {
?>
<?php
$email;$comment;$captcha;
    if(isset($_POST['email'])){
      $email=$_POST['email'];
    }if(isset($_POST['comment'])){
      $email=$_POST['comment'];
    }if(isset($_POST['g-recaptcha-response'])){
      $captcha=$_POST['g-recaptcha-response'];
    }
    if(!$captcha){
      echo '<h2>Please check the the captcha form.</h2>';
      exit;
    }
    $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=xxx&response=".$captcha."&remoteip=".$_SERVER['REMOTE_ADDR']);
    if($response.success==false)

?>


<?php
if($_REQUEST["emailid"] || $_REQUEST["phone"])
{
$to = "mail2@123.in";

 $subject = "Enquiry on tour Packages from ".$_REQUEST["name"];

 $message = "
 <html>
 <head>
   <title>Enquiry from ".$_REQUEST["name"]."</title>
  </head>
    <body>
       <p><b>Dear Sir</b>,<br> I am interested in  Tour Packages, my details are given below</p>
<table>

 <tr>
  <td><b>Full Name :  </b>".$_REQUEST["name"]."</td></tr>
     <tr><td><b>Email ID :   </b>".$_REQUEST["emailid"]."</td></tr>
      <tr><td><b>Package :   </b>".$_REQUEST["type"]."</td></tr>
  <tr><td><b>Date of Arrival:   </b>".$_REQUEST["date"]."</td></tr>
    <tr><td><b>Country:   </b>".$_REQUEST["country"]."</td></tr>
   <tr><td><b>Phone:   </b>".$_REQUEST["phone"]."</td></tr>
    <tr><td><b>Adults Number :   </b>".$_REQUEST["adults"]."</td></tr>
    <tr><td><b>Kids Number:   </b>".$_REQUEST["kids"]."</td></tr>
    <tr><td><b>Comments:   </b>".$_REQUEST["comments"]."</td></tr>
   </table>
    <br>
    <p>Regards, <br> ".$_REQUEST["name"]."</p>
    </body>
     </html>
     ";

      // Always set content-type when sending HTML email
      $headers = "MIME-Version: 1.0" . "\r\n";
       $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";

      // More headers
        $headers .= 'From: mail@123.com' . "\r\n";
        $headers .= 'Reply-To: no_reply@123.com' . "\r\n";
        $headers .= 'Cc: mail1@123.com' . "\r\n";
        $headers .= 'Bcc: mail@123.com' . "\r\n";
          if (mail($to,$subject,$message,$headers))
        {
         echo " Hi ".$_REQUEST["name"]." ! Your enquiry Sent Successfully";
           ?>
            <?php ; ?>

            <?php
            } else
               {

         echo "Mailer Error: Contact Reservation Department, call  Tel: +91 484 2381122, 4144144 or mail to emailid@xxx.com";

        }
       }
       }

         ?>

1 个答案:

答案 0 :(得分:0)

我希望这能帮到你,

第一: 下载此库(https://github.com/ivantcholakov/codeigniter-phpmailer - 或 - https://travis-ci.org/PHPMailer/PHPMailer

第二: 复制 - 将库粘贴到控制器中

以下是在代码中使用它的方法,

      private function send_forgot_password($data) {

        require(APPPATH.'controllers/mail-master/PHPMailerAutoload.php');

        // $email_encode=urlencode($data['email']);
        $mail = new PHPMailer;
        // $mail->SMTPDebug = 3;

        $mail->isSMTP();
        $mail->Host       = 'mail-host.com';
        $mail->SMTPAuth   = true;
        $mail->Username   = 'testing-alert@mail-host.com';
        $mail->Password   = '12345';
        $mail->SMTPSecure = 'tls';
        $mail->Port       = 25;

        // Email body
        $mail->From     = 'testing-alert@mail-host.com';
        $mail->FromName = 'Name';
        $mail->addAddress($data['email']);
        $mail->isHTML(true);

        $mail->Subject = 'Forgot Password';
        $mail->Body    = ' email body ';
        $mail->send(); 
}