Forum Moderators: coopster

Message Too Old, No Replies

a simple one?

multi field php sendmail

         

mattclayb

4:36 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Hi,
This is probably a stupid question, but something is going wrong,

I want to send the contents of a form from Flash via PHP through email. Now I can do this fine when my email message 'body' is made from one variable, but for some reason when I try to gather multiple variables (from multiple fields in the form) and send these as the message body, nothing happens,

any ideas?

oh and heres my script (probably very wrong)

<?php
$sendTo = "enquiries@example.com";
$subject = "Website Quote Enquiry";
$headers = "From: " . $_POST["name"];
$headers .= "<" . $_POST["email"] . ">\r\n";
$headers .= "Reply-To: " . $_POST["email"] . "\r\n";
$headers .= "Return-Path: " . $_POST["email"];
$EcompName = $_POST["compName"];
$EcontName = $_POST["contName"];
$Eemail = $_POST["email"];
$Etel = $_POST["tel"];
$Edetails = $_POST["details"];
$message = $EcompName $EcontName $Eemail $Etel $Edetails;
mail($sendTo, $subject, $message, $headers);
?>

cheers,

[edited by: jatar_k at 5:36 pm (utc) on Aug. 16, 2005]
[edit reason] examplified [/edit]

sned

4:39 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Hi Matt ... when you create your message:

$message = $EcompName $EcontName $Eemail $Etel $Edetails;

You need to concatenate the variables with a . :

$message = $EcompName . $EcontName . $Eemail . $Etel . $Edetails;

I think that will help things out a bit.

-sned

mattclayb

4:47 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



That worked great thanks!

just one more thing, I want each variable to be on a different line in the email, I've tried this

$message = $EcompName\n . $EcontName\n . $Eemail\n . $Etel\n . $Edetails\n;

with \n and it doesn't seem to work, so will I have to produce line breaks in HTML through PHP and display the email in HTML, to make this work?

sned

4:56 pm on Aug 16, 2005 (gmt 0)

10+ Year Member



Try something like this :

$message = $EcompName . "\n" . $EcontName . "\n" . $Eemail . "\n" . $Etel . "\n" . $Edetails. "\n";

I think that would work ... you might have to put in a "\r\n" instead of just "\n" to get a line break, I think it depends on the OS.

You could also through the whole thing into one big string:

$message = "$EcompName \n $EcontName \n $Eemail \n $Etel \n $Edetails \n";

Guess it depends on how readable you want your code to be.

-sned