Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

help on a php mail form

Status
Not open for further replies.

h2mhd

Programmer
Feb 20, 2008
40
CA
hi

i have made a form in html and want to submit a contact form to a client but the formatted mail the client received is like this

<p>Visiteur : pierre lavallée</p>
<br>
<p>Courriel : hfhfhhf@abc.com</p> <br> <p>Province : </p> <br> <p>Téléphone : 4507460632</p> <br> <p>Fax : </p> <br>
<p>Message: essai pour voir!</p>

is there any way to remove the html tag? put the courriel province and telephone on a different line in the mail?

heres the code i use

<?php
//$owner_email = $_POST["owner_email"];
$headers = 'From:' . $_POST["email"];
$subject = 'Un message de vos visiteur : ' . $_POST["name"];
$messageBody = "";

if($_POST['name']!='nope'){
$messageBody .= '<p>Visiteur : ' . $_POST["name"] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['email']!='nope'){
$messageBody .= '<p>Courriel : ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}else{
$headers = '';
}
if($_POST['state']!='nope'){
$messageBody .= '<p>Province : ' . $_POST['state'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['phone']!='nope'){
$messageBody .= '<p>Téléphone : ' . $_POST['phone'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['fax']!='nope'){
$messageBody .= '<p>Fax : ' . $_POST['fax'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}
if($_POST['message']!='nope'){
$messageBody .= '<p>Message: ' . $_POST['message'] . '</p>' . "\n";
}

if($_POST["stripHTML"] == 'true'){
$messageBody = strip_tags($messageBody);
}

try{
if(!mail("hugo@h2minfo.com", $subject, $messageBody, $headers)){
throw new Exception('mail failed');
}else{
header('Location: ../index-4.html');
exit;
}
}catch(Exception $e){
echo $e->getMessage() ."\n";
}
?>

thanks for your help

 
To remove the HTML tags from the output, you need to remove them from your PHP.

You can specify a line break with \n.
 
ca sera mieux, surement, d'utiliser le format html et incluire les 'headers' qui informent le client mel de rendre proprement le text sur l'ecran. Normallement, avec ce genre de message (multipart) on rajoute le meme message dans un format textuel (sans html) ainsi que les clients mels plus anciens puissent egalement bien rendre les messages.

le tout c'est fastoche avec phpmailer (GPL).
 
i would like to keep html tags but not want them to appear in the mail we received

heres the mail i received

<!DOCTYPE html>
<html xmlns="<head>
<title>Information</title>
</head>
<body>
<p>Visiteur : user</p>
<br>
<p>Courriel : abc@abc.com</p>
<br>
<p>Province : </p>
<br>
<p>Téléphone : 465328748723</p>
<br>
<p>Fax : </p>
<br>
<p>Message: sadfkjhsafhsjfas
fas
fd
as
df
asd
asd
as
d
as
d
</p>
</body>
</html>

is there a way to do that?

thanks a lot
 
You are not making any sense. If you don't want to have HTML tags appear in the email then you would not want to include them in the PHP that generates the email.

Code:
if($_POST['email']!='nope'){
$messageBody .= '<p>Courriel : ' . $_POST['email'] . '</p>' . "\n";
$messageBody .= '<br>' . "\n";
}

...should look like this...

Code:
if($_POST['email']!='nope'){
$messageBody .= "Courriel : " . $_POST['email'] . "\n\n";
}

As jpadie notes, the ideal situation is to generate multipart mail, which includes both HTML and plain text versions. However, the HTML in your sample is useless, even for HTML mail clients. Your HTML only presents line breaks (<p>). It would not generate anything better than a plain text version.

If you choose to create multipart mail, here is a sample template...

Code:
<?php

$subject = "Your mail subject line";
$to = "you@myniftywebsite.com";
$from = "info@myniftywebsite.com";
$fromname = "My Nifty Web Site";
$replies = "noreply@myniftywebsite.com";

$notice_text = "This is a multi-part message in MIME format.";

$plain_text = "Plain text message\n\nThis is the plain text version of the message.\n\nIt has line breaks.\n\n";

$html_text = "<html>
<head>
<meta http-equiv=\"content-type\" content=\"text/html;charset=iso-8859-1\">
<title>" . $subject . "</title>
</head>
<body>
<h1>HTML message</h1>
<p>This is the HTML version of the message.</p>
<p>It has line breaks.</p>
</body></html>";

$html_text = wordwrap($html_text, 72);
$plain_text = wordwrap($plain_text, 72);

$semi_rand = md5(time());
$mime_boundary = "==MULTIPART_BOUNDARY_$semi_rand";
$mime_boundary_header = chr(34) . $mime_boundary . chr(34);

$headers = "From: $fromname <$from>\n";
$headers .= "Reply-To: $replies\n";
$headers .= "X-Sender: $from\n";
$headers .= "X-Mailer: PHP4\n";
$headers .= "X-Priority: 3\n"; //1 UrgentMessage, 3 Normal
$headers .= "Return-Path: $from\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/alternative;\n";
$headers .= "     boundary=";
$headers .= $mime_boundary_header;

$body = "$notice_text

--$mime_boundary
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

$plain_text

--$mime_boundary
Content-Type: text/html; charset=us-ascii
Content-Transfer-Encoding: 7bit

$html_text

--$mime_boundary--";

if (@mail($to, $subject, $body, $headers, "-f $from")) {
    echo "The message was sent to $to"; 
    } else {
    echo "The message was not sent."; 
    }

?>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top