PHP Mail Handler

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
jayace
Forum Newbie
Posts: 1
Joined: Mon Oct 03, 2011 11:48 am

PHP Mail Handler

Post by jayace »

i have a problem with this php mail handler. what is wrong with this code?

Code: Select all

<?php

	$emailSubject = 'PowerTech';
	$webMaster = 'someone@domain.com'
	
	$nameField = $_POST['name'];
	$emailField = $_POST['email'];
	$phoneField = $_POST['phone'];
	$messField = $_POST['mess'];
	
	$body = <<<EOD
<br><hr><br>
Name: $name <br>
Email: $email <br>
Phone Number: $phone <br>
Comments: $mess <br>
EOD;

	$headers = "From: $email \r\n";
	$headers .="Content-type: text/html \r\n";
	$success = mail($webMaster, $emailSubject, $body, $headers)

	$theResults = <<<EOD
<p>success
<a href="index.php">click here</a> to homepage
</p>
EOD;

echo "$theResults";
?>


User avatar
Celauran
Moderator
Posts: 6427
Joined: Tue Nov 09, 2010 2:39 pm
Location: Montreal, Canada

Re: PHP Mail Handler

Post by Celauran »

It looks fine at a glance, although you're displaying a success message without checking the value of $success. You haven't mentioned what isn't working, though.
User avatar
flying_circus
Forum Regular
Posts: 732
Joined: Wed Mar 05, 2008 10:23 pm
Location: Sunriver, OR

Re: PHP Mail Handler

Post by flying_circus »

at a minimum it looks like you are missing semi-colons after $webMaster and you mail function call.
User avatar
egg82
Forum Contributor
Posts: 156
Joined: Sat Oct 01, 2011 9:29 pm
Location: Colorado, USA

Re: PHP Mail Handler

Post by egg82 »

semicolons (or lack thereof) will easily kill any project

Code: Select all


         $emailSubject = "PowerTech";
         $webMaster = "someone@domain.com";
         
         $nameField = $_POST['name'];
         $emailField = $_POST['email'];
         $phoneField = $_POST['phone'];
         $messField = $_POST['mess'];
         
         $body = <<<EOD
 <br><hr><br>
 Name: $name <br>
 Email: $email <br>
 Phone Number: $phone <br>
 Comments: $mess <br>
 EOD;

         $headers = "From: $email \r\n";
         $headers .="Content-type: text/html \r\n";
         $success = mail($webMaster, $emailSubject, $body, $headers);

         $theResults = <<<EOD
 <p>success
 <a href="index.php">click here</a> to homepage
 </p>
 EOD;

echo "$theResults";
Post Reply