I’m doing this simple testing on creating form where I want the form to send email twice:
- to my email address, to notify me if somebody has reached me
- to the sender’s email address to notify him/her that the contact has been sent to me.
problem is, I could send the first email, but I couldn’t send the second one. I thought this should be easy. I may miss a line or two here. Here’s the code:
<?php
$field_email = $_POST['email'];
$mail_to = 'myemail@mydomain.com';
$subject = 'Message from a site visitor '.$field_name;
$body_message .= 'E-mail: '.$field_email."\n";
$headers = 'From: '.$field_email."\r\n";
$headersTo = 'From: '.$mail_to."\r\n";
$body_messageTo = 'Thank you for your interest';
$subjectTo = 'Thank You from Gaban';
$mail_status = mail($mail_to, $subject, $body_message, $headers);
$autoreply = mail($field_email, $subjectTo, $body_messageTo, $headersTo);
?>
the $field_email should take data directly from the “email” form from the HTML code.
Unless $_POST[’email’] contains an invalid email address, I can’t see anything wrong with it. I’d say the problem is most likely to be found in the mailserver processing the mailbox where the second email is sent to.