2017-02-07 4 views
0

Новое в php, когда я нажимаю кнопку отправки, он перезагружается на домашнюю страницу, но не отправляет электронное письмо. Интересно, что я делаю неправильно, поскольку я не знаком с PHP? Я вытащил код прямо из папки примеров phpmailer. Я также добавил перенаправление в конце, чтобы проверить действие отправки формы.PHPMailer (Form Contact Submit)

<body> 
    <header> 
    <div class="flex"> 

     <h1>Waterproofing Services Inc.</h1> 
    <nav> 
     <ul> 
      <li> 
       <a href="index.html">Home</a> 
      </li>  
      <li> 
       <a href="products.html">Products Used</a> 
      </li>  
      <li> 
       <a href="services.html">Services</a> 
      </li> 
      <li> 
       <a class="current" href="freeinspection.html">Free Inspection</a> 
      </li> 
     </ul>  
    </nav> 
    </div> 
    </header> 

    <section id="minishowcase"> 
     <div class="container"> 
     <h1>Free Inspection</h1> 
     </div> 
    </section> 

    <section id="main"> 
     <div class="flex"> 
     <h2>Let us know what Waterproofing Services Inc. can do for you.</h2> 

     </div> 
    </section> 
    <section id="form"> 
    <div class="container"> 
    <div class="flex"> 
     <form method="post" action="handler.php"> 
     Name: <input type="text" name="name" value="Name" required><br>Contact Number:<input type="number" name="number" required><br> 
     Services Needed:<textarea name="message" id="message" required>Explain the services needed...</textarea> 
     <input type="submit" value="SEND"> 
     <p>*All Fields Required*</p> 
     </form>  
    </div>  
    </div> 
    </section> 






<section id="contactus"> 
<div class="container"> 
<div class="flex"> 
<p>1852 Smoke Ridge RD <br> Malvern, AR <br></p> 
<h2 class="footban">Call Now For A Free Estimate<br>(501) 609-6487</h2> 

</div> 
</div> 
</section> 
<?php 
/** 
* This example shows how to handle a simple contact form. 
*/ 

$msg = ''; 
//Don't run this unless we're handling a form submission 
if (array_key_exists('name', $_POST)) { 
date_default_timezone_set('Etc/UTC'); 

require '/home/wsiwaterproofing/public_html/PHPMailerAutoload.php'; 

//Create a new PHPMailer instance 
$mail = new PHPMailer; 
//Tell PHPMailer to use SMTP - requires a local mail server 
//Faster and safer than using mail() 
$mail->isSMTP(); 
$mail->Host = '[email protected]'; 
$mail->SMTPAuth = true; 
$mail->SMTPSecure = 'tls'; 
$mail->Mailer = "smtp"; 
$mail->Port = 465; 
$mail->Username = "[email protected]"; 
$mail->Password = "YOYOYOYOYO"; 

//Use a fixed address in your own domain as the from address 
//**DO NOT** use the submitter's address here as it will be forgery 
//and will cause your messages to fail SPF checks 
$mail->setFrom('[email protected]', 'Ryan V'); 
//Send the message to yourself, or whoever should receive contact for  submissions 
$mail->addAddress('[email protected]', 'Ryan V'); 
//Put the submitter's address in a reply-to header 
//This will fail if the address provided is invalid, 
//in which case we should ignore the whole request 
if ($mail->addReplyTo($_POST['name'], $_POST['number'])) { 
    $mail->Subject = 'New Request from WSI'; 
    //Keep it simple - don't use HTML 
    $mail->isHTML(false); 
    //Build a simple message body 
    $mail->Body = <<<EOT 
Name: {$_POST['name']} 
Number: {$_POST['number']} 
Message: {$_POST['message']} 
EOT; 
    //Send the message, check for errors 
    if (!$mail->send()) { 
     //The reason for failing to send will be in $mail->ErrorInfo 
     //but you shouldn't display errors to users - process the  error, log it on your server. 
     $msg = 'Sorry, something went wrong. Please try again  later.'; 
    } else { 
     $msg = 'Message sent! Thanks for contacting us.'; 
    } 
} else { 
    $msg = 'Invalid email address, message ignored.'; 
} 
} 
header("Location: http://www.wsiwaterproofingservices.com/"); 

?> 
+0

он перенаправляет на главную страницу, так как ваш 'заголовок ("Location: http://www.wsiwaterproofingservices.com/");' находится вне если , попытайтесь удалить его и добавьте попытку catch для catch exception –

ответ

0

было бы здорово иметь ваш html-файл с формой. Однако форма тег должен выглядеть так:

<form name="form1" id="form1" action="php_file_with_PHPMailer.php" method="post"> 

Пожалуйста, дважды проверьте, что ваша форма тег имеет правильное действие и правильный метод.

Cheers.

+0

Извините, что я добавил данные формы. –

+0

Мне нужен код :) –

+0

жаль снова, что должно помочь вам помочь. еще раз спасибо –

0

Используйте эту строку в своем коде электронной почты, чтобы поймать ошибку, если таковая имеется.

$mail->SMTPDebug = 2;      // enables SMTP debug information (for testing) 

и следить за этим Link также проверить некоторые примеры в Officials Examples Link