1

I am calling mail function 2 times in my script as below. But I am not getting second email. below is my code...

    // Sending email to Client
    $toClient = $name . "<" . $email . ">";
    $header1 = 'From: Name 1 <'.$fromEmail.'>' . "\r\n" .
                'Reply-To: Owner <'.$fromEmail.'>' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
    $header1 .= "MIME-Version: 1.0\r\n";
    $header1 .= "Content-type: text/html\r\n";

    $mailSentToClient = mail($toClient, 'Email Sent to Owner', "Thank you for contacting, I will get back to you shortly. <br>\n-Owner", $header1);

    // Sending email to Owner
    $toOwner = 'Owner' . "<" . $ownerEmail . ">";
    $header2 = 'From: '.$name.' <'.$email.'>' . "\r\n" .
                'Reply-To: '.$name.' <'.$email.'>' . "\r\n" .
                'X-Mailer: PHP/' . phpversion();
    $header2 .= "MIME-Version: 1.0\r\n";
    $header2 .= "Content-type: text/html\r\n";

    $mailSentToOwner = mail($toOwner, 'New Message', $message, $header2);

Can someone tell me whats wrong with my code?

Thanks in Advance

Pankaj Agrawal
  • 193
  • 1
  • 1
  • 11
  • If the first one works and the second one does not it probably isn't a coding issue. – John Conde Jan 05 '18 at 19:45
  • @JohnConde I think code is correct, there is some problem with PHP. Can you pls help me to fix it – Pankaj Agrawal Jan 05 '18 at 20:01
  • @JohnConde, this is not the duplicate of PHP mail function doesn't complete sending of e-mail Question. Can you pls remove that? – Pankaj Agrawal Jan 05 '18 at 20:02
  • How is not a duplicate? Your email is not arriving. That question explains how to troubleshoot that. – John Conde Jan 05 '18 at 20:04
  • @JohnConde as per that question the mail is not sending at all. but in my case first mail is going but second mail is not going. and syntax is same for the both – Pankaj Agrawal Jan 05 '18 at 20:06
  • Exactly. So as my first comments says, it's not a coding issue. Something outside of your code is preventing your email from arriving. That question tells you how to troubleshoot that. Did you read the first answer? – John Conde Jan 05 '18 at 20:07
  • @JohnConde, I have read the first answer. I am following all the things. but still no luck. – Pankaj Agrawal Jan 05 '18 at 20:19
  • That answer covers everything this community knows about debugging PHP's failure to send an email. Asking a new question will not get any new information. I recommend doublechecking everything and trying to send each email one at a time and see what happens. If it works when there is only one email being sent on each call to that script, then you know something is blocking that second email. Same goes if you try switching the order of the emails. So, there is still more you can do for debugging this. – John Conde Jan 05 '18 at 20:22

0 Answers0