Formatting eMail

the mail() function

Moderators: macek, egami, gesf

vettenut
New php-forum User
New php-forum User
Posts: 11
Joined: Tue Aug 09, 2011 3:30 pm

Formatting eMail

Postby vettenut » Mon Dec 19, 2011 12:08 pm

I have a php file that sends eMail. How do I format the contents. Sample of what is sent now:

We have received the following information from a Survey:

Name: Robert Beyerlein
Email: topcat@vettenut.com
Phone: 123-445-7890
Did you the service you received satisfy you?: yes Were you satisfied with the quality of service?: yes Was the Brandenburg Auto Clinic web site easy to navigate?: yes Would you reccommend Brandenburg Auto Clinic to other people?: yes
Comments: My Comments

I would like to have each question/answer on a seperate line. Thank you in advance.

Current code:

<?php

///// cssend.php /////

if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
}

ini_set('error_reporting', 'E_ALL & ~E_NOTICE');



$youremail = "acdelco40108@yahoo.com"; /*put the email address here, between quotes,
the email address you want the message sent to*/


$to = $youremail;
$email = $_POST['cust_email'];
$name = $_POST['cust_name'];
$phone = $_POST['cust_phone'];
$service_satisfy = $_POST['service_satisfy'];
$quality_satisfy = $_POST['quality_satisfy'];
$website_navigate = $_POST['website_navigate'];
$reccomend = $_POST['reccomend'];
$comments = $_POST['comments'];


$headers = "From:" . $email;

$fields = array();
$fields{"cust_name"} = "Name";
$fields{"cust_email"} = "Email";
$fields{"cust_phone"} = "Phone";
$fields{"service_satisfy"} = "Did you the service you received satisfy you?";
$fields{"quality_satisfy"} = "Were you satisfied with the quality of service?";
$fields{"website_navigate"} = "Was the Brandenburg Auto Clinic web site easy to navigate?";
$fields{"reccomend"} = "Would you reccommend Brandenburg Auto Clinic to other people?";
$fields{"comments"} = "Comments";


$subject = "We have received the following information from a Survey";
$body = "We have received the following information from a Survey:\n\n";
foreach($fields as $a => $b)
{ $body .= sprintf("%20s: %s\n",$b,$_POST[$a]); }

mail ($to, $subject, $body, $headers); //send mail to owner
#end create email vars

$headers = "From:" . $to;

mail ($email, $subject, $body, $headers); //send mail to user
#end create email vars

echo "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;
URL=ThankYou2.html\"></head>";
?>

TheProdigyGuy
New php-forum User
New php-forum User
Posts: 215
Joined: Wed Dec 07, 2011 5:25 pm

Re: Formatting eMail

Postby TheProdigyGuy » Mon Dec 19, 2011 4:18 pm

Code: Select all

<?php

///// cssend.php /////

if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
}

ini_set('error_reporting', 'E_ALL & ~E_NOTICE');



$youremail = "acdelco40108@yahoo.com"; /*put the email address here, between quotes,
the email address you want the message sent to*/


$to = $youremail;
$email = $_POST['cust_email'];
$name = $_POST['cust_name'];
$phone = $_POST['cust_phone'];
$service_satisfy = $_POST['service_satisfy'];
$quality_satisfy = $_POST['quality_satisfy'];
$website_navigate = $_POST['website_navigate'];
$reccomend = $_POST['reccomend'];
$comments = $_POST['comments'];


$headers = "From:" . $email;

$fields = array();
$fields{"cust_name"} = "Name";
$fields{"cust_email"} = "Email";
$fields{"cust_phone"} = "Phone";
$fields{"service_satisfy"} = "Did you the service you received satisfy you?";
$fields{"quality_satisfy"} = "Were you satisfied with the quality of service?";
$fields{"website_navigate"} = "Was the Brandenburg Auto Clinic web site easy to navigate?";
$fields{"reccomend"} = "Would you reccommend Brandenburg Auto Clinic to other people?";
$fields{"comments"} = "Comments";


$subject = "We have received the following information from a Survey";
$body = "We have received the following information from a Survey" .PHP_EOL;
foreach($fields as $a => $b)
{ $body .= sprintf("%20s: %s" .PHP_EOL,$b,$_POST[$a]); }

mail ($to, $subject, $body, $headers); //send mail to owner
#end create email vars

$headers = "From:" . $to;

mail ($email, $subject, $body, $headers); //send mail to user
#end create email vars

echo "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;
URL=ThankYou2.html\"></head>";
?>


Out:

Code: Select all

We have received the following information from a Survey
                Name:
               Email:
               Phone:
Did you the service you received satisfy you?: yes
Were you satisfied with the quality of service?: yes
Was the Brandenburg Auto Clinic web site easy to navigate?: yes
Would you reccommend Brandenburg Auto Clinic to other people?: yes
            Comments:





Second version:

Code: Select all

<?php

///// cssend.php /////

if (!ini_get('display_errors')) {
ini_set('display_errors', 1);
}

ini_set('error_reporting', 'E_ALL & ~E_NOTICE');



$youremail = "acdelco40108@yahoo.com";
/*put the email address here, between quotes,
acdelco40108@yahoo.com the email address you want the message sent to*/


$to = $youremail;
$email = $_POST['cust_email'];
$name = $_POST['cust_name'];
$phone = $_POST['cust_phone'];
$service_satisfy = $_POST['service_satisfy'];
$quality_satisfy = $_POST['quality_satisfy'];
$website_navigate = $_POST['website_navigate'];
$reccomend = $_POST['reccomend'];
$comments = $_POST['comments'];


$headers = "From:" . $email;

$fields = array();
$fields{"cust_name"} = "Name";
$fields{"cust_email"} = "Email";
$fields{"cust_phone"} = "Phone";
$fields{"service_satisfy"} = "Did you the service you received satisfy you?";
$fields{"quality_satisfy"} = "Were you satisfied with the quality of service?";
$fields{"website_navigate"} = "Was the Brandenburg Auto Clinic web site easy to navigate?";
$fields{"reccomend"} = "Would you reccommend Brandenburg Auto Clinic to other people?";
$fields{"comments"} = "Comments";


$subject = "We have received the following information from a Survey";
$body = "We have received the following information from a Survey" .PHP_EOL;
foreach($fields as $a => $b)
{

   if ($a=="service_satisfy" || $a=="quality_satisfy" || $a=="website_navigate" || $a=="reccomend")
   {
    $body .=sprintf("%20s: %s" . PHP_EOL,$b,PHP_EOL .$_POST[$a]) .PHP_EOL;
   }
   else
   {
     $body .= sprintf("%20s: %s" . PHP_EOL,$b,$_POST[$a]);
   
   }
    }
    unset($a,$b);

@mail ($to, $subject, $body, $headers); //send mail to owner
#end create email vars

$headers = "From:" . $to;

@mail ($email, $subject, $body, $headers); //send mail to user
//mail ($email, $subject, $body, $headers); //send mail to user
#end create email vars

echo "<head><META HTTP-EQUIV=\"Refresh\" CONTENT=\"2;
URL=ThankYou2.html\"></head>";
?>






Output:

Code: Select all

We have received the following information from a Survey
                Name:
               Email:
               Phone:
Did you the service you received satisfy you?:
yes

Were you satisfied with the quality of service?:
yes

Was the Brandenburg Auto Clinic web site easy to navigate?:
yes

Would you reccommend Brandenburg Auto Clinic to other people?:
yes

            Comments:


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 0 guests