PDA

View Full Version : mail()



Patch^
February 7th, 2008, 04:24 PM
hey,

I'm working with a mail php script, I've used it plenty of times before but I can't seem to get it to do anything. I've tried my own host and some one elses. So there must be something I'm doing wrong.

Here is the code:




<?php

if(isset($_POST['submit']))

{

$to = "test@test.com";

$subject = "Test PHP Email";

$message = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

$headers = "From : Test PHP Email <noreply@testphpemail.com>";

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

}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title>Test Email</title>

</head>

<body>

<p>Send a Test PHP Email to Test</p>

<form name="test" method="post">

<input type="submit" name"submit" value="Submit" />

</form>

</body>

</html>




It looks ok to me, perhaps mail is turned off in the php.ini ? (Not sure)

It's only test code I'm showing at the moment. It's not exactly how i have it setup for the script I'm using, but the mail section is identical.


Any help advice would be most appreciated.

Cheers.

DarkAz
February 7th, 2008, 05:37 PM
The problem isn't with the mail() section of the script, rather the statement checking for $_post['submit']

if you echo out your post variables:


echo "<pre>" . print_r($_POST,true) . "</pre>";

you will see that there is nothing set

I'm sure that when put into production you'll have some other fields in the form which is being submitted (and that you'll be validating things to avoid spambots and the like) - for the interim try adding in a hidden input to validate for:


<input type="hidden" name="foo" value="bar" />


if($_POST['foo'] == 'bar')

Patch^
February 7th, 2008, 08:25 PM
still does nowt, thanks though

gregmax
February 7th, 2008, 09:42 PM
Look at this line:



<input type="submit" name"submit" value="Submit" />


it should be like this:



<input type="submit" name="submit" value="Submit" />


you missed the "=". Also, try not setting the same name as the input type. I just have bad experience with it and javascript, imo.

Patch^
February 8th, 2008, 06:17 AM
thanks, but still not working.

Patch^
February 8th, 2008, 06:33 AM
I've even just tried doing this:




<?php

$to = "test@test.com";

$subject = "Test PHP Email";

$message = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

$headers = "From : Test PHP Email <noreply@testphpemail.com>";

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

?>



That should work, but still no luck!!?!!?

Zaid_W1red
February 8th, 2008, 10:07 AM
does your host require you use ini_set to specify/verify a sender?

gregmax
February 8th, 2008, 10:38 AM
The code looks fine, its probably just the host that preventing you to send mail from php.... like maybe they turned that functionality off or something in .ini file... or didn't install it ... :/ ?

Patch^
February 8th, 2008, 11:15 AM
Thanks for all the help and support guys, much appreciated. I'm going to go and kick my host up the arse.

kinderjit
February 9th, 2008, 02:06 AM
<?php

if($_POST['submit'] != "")

{

$to = "test@test.com";

$subject = "Test PHP Email";

$message = "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";

$headers = "From : Test PHP Email <noreply@testphpemail.com>";

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

}

?>