Skip to main content
Known Participant
December 29, 2010
Question

PHP mail script

  • December 29, 2010
  • 1 reply
  • 631 views

I have a simple mailto script for emailing the contents of a form to me and have 2 questions

1) if i put in code to redirect to a different page after the mail command will this gaurantee that the mail command executes fully before the redirect command is run.

2) according the the PHP manual (http://uk.php.net/manual/en/function.mail.php) the mail command returns true or false depending on if or not the mail was successfully sent. can i use this to determine what code is run next with an if statement and how do i do so?

also if the mail fails to send how long would the script keep trying for before it gives up and returns the false value

This topic has been closed for replies.

1 reply

December 29, 2010

1.) yes - if your syntax is correct.

2.) yes - provide your code and we'll show you how.

3.) never. It tries to process once and that's it.

Known Participant
December 29, 2010

this be my code as u asked for

<?
$name = $_POST['Name'];
$email = $_POST['Email'];
$phone = $_POST['Phone'];


$message = $_POST['Message'];

$headers = "From: $email" . "\r\n" .
    "Reply-To: $email" . "\r\n" .

mail("me@email.com", "enquiry from website", "NAME:$name

PHONE:$phone

MESSGAGE:
$message",$headers);
?>

December 29, 2010

<?php

// if the message has been submitted from the form then process the email

if (isset($_POST['Message'])) {

// form processing script here

// put whatever else you want to do after the form has been processed here.

// if no message was posted then display an error message

} else {

echo "Your message has not been processed because a message has not been submitted!";

} ?>

Here's a basic example that says "if a message has been submitted from the form then process the form and send an email else display an error message. You can add conditions to your if statement where if Message isset && Email isset && Phone isset etc. then process email script. Lookup php if/else statements for more info.