contact form email

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
Stefan83
Forum Newbie
Posts: 5
Joined: Tue Apr 03, 2007 10:13 am

contact form email

Post by Stefan83 »

Hi

I'm having difficulties sending the contents from a contact form to the body of an email.

The email delivers no problem, but only the message is displayed in the body, I'd like to include the email address, name and telephone of the sender in the body of the email.

Could someone please shed some light on this? thanks!

Code: Select all

<?php
ini_set("sendmail_from", "mail@myemail.com");

$to = "mail@myemail.com";
$name = $_POST['name'];
$email_from =$_POST['email'];
$email = $_POST['email'];
$telephone = $_POST['telephone'];
$message = $_POST['message'];

$subject = "Subject";
$body = "From $name, $telephone, $email, \n\n$message, \n\n$name";
$headers =
"From: $email_from .\n";
"Reply-To: $email_from .\n";

mail($to, $subject, $body, $name);

$sent = mail($to, $subject, $message, $headers, '-f'.$email_from);
?>

User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Re: contact form email

Post by Christopher »

Code: Select all

$sent = mail($to, $subject, $body, $headers, '-f'.$email_from);
(#10850)
Stefan83
Forum Newbie
Posts: 5
Joined: Tue Apr 03, 2007 10:13 am

Re: contact form email

Post by Stefan83 »

Perfect! Thanks Christopher
Stefan83
Forum Newbie
Posts: 5
Joined: Tue Apr 03, 2007 10:13 am

Re: contact form email

Post by Stefan83 »

I have one more question. How would I setup an auto response after the email from the contact form has been delivered? Or would it be possible for the user to click a check box to request a copy of the email they send via the contact form? Thanks in advance!
User avatar
Jonah Bron
DevNet Master
Posts: 2764
Joined: Thu Mar 15, 2007 6:28 pm
Location: Redding, California

Re: contact form email

Post by Jonah Bron »

[syntax="php]if ($_POST['send_copy_to_me'] == '1'){
$sent_to_self = mail($email_from, $subject, $body, $headers, '-f'.$email_from);
}[/syntax]

Just plop a checkbox into your form page.

Code: Select all

<input type="checkbox" name="send_copy_to_me" value="1" />
Post Reply