Log in

View Full Version : send mail php



dianadolce
01-10-2008, 03:21 PM
Can any one help me set up my send mail php script to do what I need it to do? In the form I added 2 more fields called company and phone. As the script is written right now only the name, email and message will show up in the submitted email. I have tried to add the 2 new fields in many ways, but I get an error. Just not doing it right because I am not php savvy. What I want to see in the submitted email is this order:

Name:
Company:
Email:
Phone:
Message:

(the form is in a flash file so can't show you that, but it does work with the php as shown below, just not how I want it to)

***************************



<?
//Send Mail PHP
//
//Upload this file to the root of your web directory

if(!empty($HTTP_POST_VARS['sender_mail']) || !empty($HTTP_POST_VARS['sender_message']) || !empty($HTTP_POST_VARS['sender_name']))

{
//Insert Address(s) to send the mail to
$to = "dianadolce@gmail.com";

//Subject
$subject = "Message from Amadeus Brochure Form";

//Body
$body = stripslashes($HTTP_POST_VARS['sender_message']);

$body .= "\n---------------------------\n";

$body .= "Mail sent by: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";

$body .= "\n\n";

$body .= "\nservice powered by dhsartstudio.com\n";

$header = "From: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";

$header .= "Reply-To: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";

$header .= "X-Mailer: PHP/" . phpversion() . "\n";

$header .= "X-Priority: 1";

//Mail Sentinel
if(@mail($to, $subject, $body, $header))

{
//Return Mail Status to Flash Form
echo "output=sent";

} else {

echo "output=error";

}

} else {

echo "output=error";

}

?>


***********************

Thank you, thank you for looking at this and helping me understand what has to happen.

Diana:)

Wrapped the code in
tags

boogyman
01-10-2008, 03:59 PM
welcome to the forums, and thank you for using a descriptive title.
Please review our Posting Policies (http://www.dynamicdrive.com/forums/showthread.php?p=125904) especially in regards to posting computer code within a thread... Rule #8



//Body
$body = stripslashes($HTTP_POST_VARS['sender_message']);

$body .= "\n---------------------------\n";

$body .= "Mail sent by: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";

$body .= "\n\n";

$body .= "\nservice powered by dhsartstudio.com\n";

just add another line to the body to include whatever you call the phone and company and any other additional values



...
$body .= "Mail sent by: " . $HTTP_POST_VARS['sender_name'] . " <" . $HTTP_POST_VARS['sender_mail'] . ">\n";

$body .= "Phone Number: ". $HTTP_POST_VARS['phone'] ."\n";

$body .= "Company: ". $HTTP_POST_VARS['company'] ."\n";

...


That would put the phone and company, but it follows the format of



$body .= "Title: ". $HTTP_POST_VARS['_form_name_element_'] ."\n";

to explain that
$body .= is to initiate contantenate something to the end of the string, in your case the main content section of the email
"Title: ". will give the reference to some type of title. Please not that it must be enclosed within quotation marks, as that is part of PHP Syntax.
$HTTP_POST_VARS['_form_name_element_'] the name of the element as it appears in the form so for the phone text input form field you would put <input type="text" name="_form_name_element_" value="">
."\n"; create a new line character (character return), so the next instance of the body tag is on a new line.

if you follow that format you can put as many new elements as you wish.

dianadolce
01-10-2008, 04:06 PM
Wonderful, I will try that again. I can see where I made a mistake previously trying to do this. We let you know, thanks Boogyman