2016-09-17 197 views
0

我使用AJAX和PHP发送电子邮件与联系人表单中的数据。我使用下面的PHP:发送PHP确认电子邮件管理员电子邮件发送

  if (mail($recipient, $subject, $email_content, $email_headers)) { 
       // Set a 200 (okay) response code. 
       http_response_code(200); 
      } else { 
       // Set a 500 (internal server error) response code. 
       http_response_code(500); 
       echo "Oops! Something went wrong and we couldn't send your message."; 
      } 

这是工作的罚款,但如果这第一封电子邮件被发送,我也想送一个确认邮件用新的参数。我想我应该能够只设置其他邮件()函数,如200响应代码之后:

 if (mail($recipient, $subject, $email_content, $email_headers)) { 
      // Set a 200 (okay) response code. 
      http_response_code(200); 
      mail($email, $confirmation_subject, $confirmation_content, $confirmation_headers); 
     } else { 
      // Set a 500 (internal server error) response code. 
      http_response_code(500); 
      echo "Oops! Something went wrong and we couldn't send your message."; 
     } 

但是这是造成发送电子邮件既不。如果发送管理员电子邮件,实施确认电子邮件的正确方法是什么?

+1

这看起来不错,所以你需要做一些基本的调试,看看发生了什么。使用调试器来遍历代码。 – Synchro

回答

1

当您发送回头时,执行基本停止。我从来没有见过它的记录,但我以前一直在这个位。尝试切换这两种秩序:

http_response_code(200); 
mail($email, $confirmation_subject, $confirmation_content, $confirmation_headers); 

mail($email, $confirmation_subject, $confirmation_content, $confirmation_headers); 
http_response_code(200);