Arrays in mail with <select multiple>

the mail() function

Moderators: macek, egami, gesf

cad
New php-forum User
New php-forum User
Posts: 1
Joined: Thu Jul 21, 2011 8:08 pm

Arrays in mail with <select multiple>

Postby cad » Thu Jul 21, 2011 8:25 pm

Gentlemen and ladies,

I am having the hardest time trying to debug this script. I have a contact form that has several text box fields and one <select multiple> box. The text box processes through the script but the <select multiple> does not.

I am trying to email an array of sorts. When a user selects two choices on the list of choices, I want the email to show this:

Name: name variable
Company: company variable
Email: email variable
Phone Number: phone variable
Inquiry: inquiry variable

but on the inquiry variable, I want it separated with </br>'s.

Here's my code - redacted:

Code: Select all

<?

$name = $_POST['name'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$inquiry = $_POST['inquiry'];



$to  = "myemail";

/* subject */
$subject = "Contact Form";


/* message */
$message= "
<strong>Contact Form</strong><br><br>
<strong>Name:</strong>        $name<br>
<strong>Company:</strong>     $company<br>
<strong>Phone:</strong>       $phone<br>
<strong>Email:</strong>         $email<br>
foreach ($inquiry as $i) { 
echo "
<strong>Inquiry:</strong>     $i<br>";
}
";

/* To send HTML mail, you can set the Content-type header. */
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

/* additional headers */
$headers .= "To: Me <myemail>\r\n";
$headers .= "From: Contact Form <contactform@myemail>\r\n";

mail($to, $subject, $message, $headers);
?>


Can someone find a way for the inquiry variables to be separated using breaks and still look good on the email form?

Regards,

Chris

User avatar
bigjoe11a
New php-forum User
New php-forum User
Posts: 128
Joined: Wed Aug 31, 2011 3:55 am
Location: USA
Contact:

Re: Arrays in mail with <select multiple>

Postby bigjoe11a » Tue Sep 27, 2011 1:48 pm

Hi! cad, I will need to see your html page all so.

Here's what you should do.

Code: Select all

<?php

$name = $_POST['name'];
$company = $_POST['company'];
$phone = $_POST['phone'];
$email = $_POST['email'];
$inquiry = $_POST['inquiry'];



$to  = "myemail";

    /* subject */
$subject = "Contact Form";


    /* message */
$message = <<< heredoc
<strong>Contact Form</strong><br>
<strong>Name:</strong>        $name<br>
<strong>Company:</strong>     $company<br>
<strong>Phone:</strong>       $phone<br>
<strong>Email:</strong>         $email<br>
heredoc;
   
foreach ($inquiry as $i) {
echo "<strong>Inquiry:</strong>     $i<br>";
}
       
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1";
/* additional headers */
$headers .= "To: Me <myemail>";
$headers .= "From: Contact Form <contactform@myemail>";

mail($to, $subject, $message, $headers);

?>


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest

cron