2

I have the following php mail file :

<?php $name = $_POST['name'];
$email = $_POST['email'];
$choice = $_POST['choice'];$num = $_POST['num'];
$choice1 = $_POST['choice1'];$num1 = $_POST['num1'];
$phone= $_POST['phone'];
$town= $_POST['town'];
$formcontent="
Name: $name \n
Number: $phone \n
Choice: $choice Amount:$num
Choice: $choice1 Amount:$num1
Town: $town \n
Email: $email" ;
$recipient = "info@domain.com";
$subject = "Contact Form";
$mailheader = "From: $email \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
echo "Thank You!";?>

Can I add the $email to the recipients? I want to add the email entered in the form into the recipients that receive the email. (info@domain.com and the email entered in the form ($email = $_POST['email'];) will receive the email.

1 Answers1

2

You can add multiple email addresses to $recipient by separating them with commas. Try this.

$recipient = "info@domain.com, $email";

Edit

Here is the whole thing.

<?php

    $name = $_POST['name'];
    $email = $_POST['email'];
    $choice = $_POST['choice']; $num = $_POST['num'];
    $choice1 = $_POST['choice1']; $num1 = $_POST['num1'];
    $phone= $_POST['phone'];
    $town= $_POST['town'];

    $formcontent = "
    Name: $name \n
    Number: $phone \n
    Choice: $choice Amount:$num
    Choice: $choice1 Amount:$num1
    Town: $town \n
    Email: $email";

    $recipient = "info@domain.com, $email";
    $subject = "Contact Form";
    $mailheader = "From: $email \r\n";
    mail($recipient, $subject, $formcontent, $mailheader) or die("Error!");
    echo "Thank you";

?>
Jack Humphries
  • 13,056
  • 14
  • 84
  • 125
  • Hmmm. Are you sure all of the values are being posted? See this link: http://stackoverflow.com/questions/4913817/catching-php-mail-errors-and-showing-reasonable-user-error-message. – Jack Humphries Jan 09 '13 at 18:37
  • I'm not sure what to say. It works for me when using the code above. Copy and paste the whole block of code into the PHP file. – Jack Humphries Jan 09 '13 at 19:55