PHP Mailer - help

Soldato
Joined
15 Feb 2003
Posts
10,167
Location
Europe
Hi,

I use this script to enable people to send an email from my site. However rather than it just saying thank you. I want it to redirect to particular page.

How should it be modified to do that?


Code:
<?php

if ($_SERVER['REQUEST_METHOD'] != 'POST') exit; // Quit if it is not a form post

// quick way clean up incoming fields
foreach($_POST as $key => $value) $_POST[$key] = urldecode(trim($value));

// get form data into shorter variables
// each $_POST variable is named based on the form field's id value
$name   = $_POST['name'];
$telephone = $_POST['telephone'];
$sender_email = $_POST['sender_email'];
$message = $_POST['message'];
$code    = $_POST['code'];

$errors  = array(); // array of errors

// basic validation
if ($name == '') {
  $errors[] = "\n\n - Please enter your name. ";
}


if ($telephone == '') {
  $errors[] = "\n\n - Please enter your telephone. ";
}

if ($sender_email == '') {
  $errors[] = "\n\n - Please enter your email address. ";
}

if (sizeof($errors) == 0) {
  // only check the code if there are no other errors
  require_once 'securimage/securimage.php';
  $img = new Securimage;
  if ($img->check($code) == false) {
    $errors[] = "\n\n Incorrect security code entered";
  } // if the code checked is correct, it is destroyed to prevent re-use
}

if (sizeof($errors) > 0) {
  // if errors, send the error message
  $str = implode("\n", $errors);
  die("There was an error with your submission.  Please correct the following:" . $str);
}

require_once('class.phpmailer.php');

$time = date('r');
$body = "Name: ".$name."<br />";
$body .= "Telephone: ".$telephone."<br />";
$body .= "Email: ".$sender_email."<br />";
$body .= "Message: ".$message."<br />";


// send email

$mail             = new PHPMailer();
$mail->CharSet = "UTF-8";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "mail.mydomain.com"; // sets the SMTP server
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "[email protected]"; // SMTP account username
$mail->Password   = "mypassword";        // SMTP account password

// ** CHANGE BELOW  ** 

$mail->SetFrom('[email protected]', '[email protected]'); // Who the email is being sent FROM
$mail->AddReplyTo("[email protected]","My Name"); // REPLY TO
$mail->Subject = "Request from website";

// ******************* 

$mail->MsgHTML($body);

$address = "[email protected]"; // ** Who the email is being sent TO
$mail->AddAddress($address, "Me"); // ** Who the email is being sent TO

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else


die('Thank you'); // send success indicator
?>


Thanks
 
Back
Top Bottom