Jump to content

PHP mail error


Callum

Recommended Posts

Hi when ever I submit the form, I recieve the email but the data in the $msg varible is not sent. It just sends blank. Can someone show me whats wrong?here is the form

<form action="payment.php" method="POST">Name:       <input type="text" name="name" size="20"/>Email: <input type="text" name="email" size="20"/><br>Site title:   <input type="text" name="title" size="20" />No. of pages <input type="text" name="pages" size="13" /><br>Site topic: <input type="text" name="topic" size="20" /><br><span><p>Images</p></span><input type="radio" name="images" value="have"> I have my own web images<br><input type="radio" name="images" value="need"> I want Daemon Studios to make me Images<br>Other details:<br /><textarea name="other" cols="40" rows="4"></textarea><br><p>We will contact you shortly for further details about your design. <br> Click Purchase to continue to the payment page.</p><input type="submit" name="submit" value="Purchase" /></form>

here is the php code

<?php $name = $POST['name']; $email = $POST['email'];$sitetitle = $POST['title'];$npages = $POST['pages'];$sitetopic = $POST['topic'];$images = $POST['images'];$other = $POST['other'];$to = "tired_of_being_hacked@hotmail.co.uk";$re = "Web Site order";$msg = $name;$email;$sitetitle;$npages;$sitetopic;$images;$other;mail($to, $re, $msg);?>

Thanks Callum

Link to comment
Share on other sites

Try putting that big mail string in quotation marks. You might be happier too if you used a \n instead of the ; to separate the different items.I'm not sure why you're not getting at least the $name inside your message. Try echoing $msg before you send the mail, just to see what's really in there. If it's not what you think, try var_dump($_POST) to see what the pieces are.And of course eventually you'll want to test your POST vars to see if they're empty before you start doing stuff with them.

Link to comment
Share on other sites

$msg = $name;$email;$sitetitle;$npages;$sitetopic;$images;$other;^ that is almost certainly wrong.That line basically becomes $msg = $name; followed by a load of empty statements which do nothing. If you want to make $msg all of those variables then you probably want to concatenate them. Like this:

<?php$a = 'Hello ';$b = 'World';$hello = $a . $b; // <-- this is the concatenation, it combines the two strings $a and $b and the result is stored in $hello.echo $hello; // OUTPUT: "Hello World"?>

If you're lazy then you can also interpolate them with double quotes, but I tend not to use them simply because it's a less efficient way of doing the same thing.

<?php$a = 'Hello';$b = 'World';$hello = "$a $b"; // <-- this is an interpolated string, the variables are substituted for their contents (this does not happen with single quotes).echo $hello; // OUTPUT: "Hello World"?>

EDIT: Additional information, that isn't relevant to your case because you're not echoing the data, but echo is a special case for this sort of string combination. The example I've given can be most efficiently given as (keeping the two variables, pretending they're dynamic input):

<?php$a = 'Hello ';$b = 'World';echo $a,$b; // <-- note the comma in this case, echo allows this and it's slightly faster, print does not.?>

EDIT2: Oh, and you're using $POST, it's $_POST.

Link to comment
Share on other sites

I can't believe I missed the post error lolbut more importantlyhow do I get the variables to display on different lines?Currently it's this

$msg = $var1 . $var2 . $var3 . $var4 . $var5;

But as you can imagine, the email is impossible to read with all the variables side by sideI tired this, but it just came up with errors not allowing the "\" character

$msg = $var1 . \n $var2 . \n $var3 . \n $var4 . \n $var5;

Could someone tell me how to display a new varialbe on a new line?EDIT: I'm relatively new to PHP so don't be too harsh :/

Link to comment
Share on other sites

You have to put strings within quotes.Here's one way to add line breaks:

$msg = $var1 . "\n" . $var2 . "\n" . $var3 . "\n" . $var4 . "\n" . $var5;

And another way:

$msg = "{$var1}\n{$var2}\n{$var3}\n{$var4}\n{$var5}";

And yet another way:

$msg = "{$var1}{$var2}{$var3}{$var4}{$var5}";

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...