简体   繁体   中英

form not redirecting or sending email

Having an issue with my mailer script. When an email is sent it doesn't redirect to my chosen page it sits on mail.php which os the logic file. Having some issues understanding what the top section is asking me for too.

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>

<?php
require 'c:\php\includes\PHPMailerAutoload.php';

$mail = new PHPMailer;

$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'smtp.website.com'; // Specify main and backup server
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'my@website.com';                            // SMTP username
$mail->Password = '******';                         // Enable encryption, 'ssl' also accepted
$mail->Port = 25;

$mail->From = 'http://iamdanbarrett.com';
$mail->FromName = 'Contact Form';

$mail->addAddress('iamdanbarrett.com');               // Name is optional


$mail->WordWrap = 50;                                 // Set word wrap to 50 characters

$mail->isHTML(true);                                  // Set email format to HTML

$mail->Subject = 'General Enquiries';

$mail->Body    = "<html><body>Name: " . $_POST["Name"] . "<br><br>Email: " . $_POST["Email"] . "<br><br>Message: " . $_POST["Message"];

// $mail->Body    = 'Details below:<br><hr><br><br><b>Shortlist:</b><br>' . $_POST["strShortlist"] . '<br><br><b>Company:</b> ' . $_POST["strCompany"] . '<br><br><b>Full Name:</b> ' . $_POST["strFullname"] . '<br><br><b>Email:</b> ' . $_POST["strEmail"] . '<br><br><b>Contact No:</b> ' . $_POST["strContactNo"] . '<br><br><b>No of People:</b> ' . $_POST["strNoOfPeople"] . '<br><br><b>Start Date:</b> ' . $_POST["strDate"] . '<br><br><b>Requirements:</b> ' . $_POST["strRequirements"] . '<br><br><b>Other:</b> ' . $_POST["strOther"] . '<br><br><b>Salesperson:</b> ' . $_POST["strSalesperson"];

if(!$mail->send()) {
   echo '';
   echo '';
   exit;
} else {

}

?>

</head>

<body>

<script>
  $( document ).ready(function() {
    window.location.href = "http://iamdanbarrett.com/;
  });
</script>

Why do you have to bring Javascript in here ? Use the PHP's header() instead.

if(!$mail->send()) {
        die("Mail was not sent!");
} else {
    header("location:http://iamdanbarrett.com/");
    exit;
}

You can use php header function. Put below code in your else part.

header("Location:http://iamdanbarrett.com/");exit;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM