Page 1 of 1

PHP email

Posted: Tue Jun 12, 2007 2:03 am
by webdev
I creating a simple feedback form using PHP and HTML.

This executes the mail function with four parameters. It mails to the recipient with a subject, body, and from. If it does not execute, it will print "Message failed!".

Code: Select all

<?php
$name = $_POST['name'];
$message = $_POST['comments']; 
$from = $_POST['email'];
$mail_sent = $_POST['submit']; 

$to = 'paul.crawford@austasiagroup.com';
$subject = 'Kiri Park Enquiry'; 
$body = "The following enquiry was submitted via the Kiri Park website on ".date('l, d M Y H:i:s') . "\n\nName: ". $name ."\n\nEmail: ". $from ."\n\nComments: ". $message;
$mail_sent = mail( $to, $subject, $body, "From: $from" );

//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed"
if ($mail_sent)
{
	echo "<div class=\"bodytext\">Thank you, ". $name .". Your mail was sent successfully.</div>";
} else {
	echo "<div class=\"bodytext\">Mail failed<!/div>";
}
?>
What is the code if the user does not execute and will print "Message failed"?

Any helps would be great!

Posted: Tue Jun 12, 2007 3:59 am
by Rovas
First check if the user completes the given fields using isset and empty, then validate (is_string )the data inputed and after this use the code you put.

Posted: Tue Jun 12, 2007 4:47 am
by arukomp
Also, just a simple mistake here:

Code: Select all

Mail failed<!/div>
Should be

Code: Select all

Mail failed!</div>

Posted: Tue Jun 12, 2007 7:59 pm
by webdev
Rovas, I don't know what do you mean. Can you give me an example please?

Thanks alot.
Paul