PHP email

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
webdev
Forum Commoner
Posts: 25
Joined: Tue Jun 05, 2007 2:07 am

PHP email

Post 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!
Rovas
Forum Contributor
Posts: 272
Joined: Mon Aug 21, 2006 7:09 am
Location: Romania

Post 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.
arukomp
Forum Contributor
Posts: 113
Joined: Sun Sep 24, 2006 4:22 am

Post by arukomp »

Also, just a simple mistake here:

Code: Select all

Mail failed<!/div>
Should be

Code: Select all

Mail failed!</div>
webdev
Forum Commoner
Posts: 25
Joined: Tue Jun 05, 2007 2:07 am

Post by webdev »

Rovas, I don't know what do you mean. Can you give me an example please?

Thanks alot.
Paul
Post Reply