我建立了一个网站,其中包含联系表格,并向用户发送邮件“电子邮件,姓名,号码和消息”。我已经使用了Swift邮件程序,下面是代码。 它回应“Hello World”和“Result”,但不发送任何邮件或显示Thank you消息。如果有人可以帮助我,我将会有很大的帮助。
<body>
<?php
echo "Hello world!";
session_start();
//Email information
$admin_email = "mymail@gmail.com";
$email = $_REQUEST['email'];
$name = $_REQUEST['name'];
$number = $_REQUEST['number'];
$comment = $_REQUEST['comment'];
//if "email" variable is filled out, send email
// if (isset($_REQUEST['email'])) {
require_once 'swiftmailer/lib/swift_required.php';
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 587)
->setUsername('example@domain.com')
->setPassword('password')
;
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Tours Enquiry')
->setFrom(array($email => $name))
->setTo(array('example@domain.com'=> 'Some Name'))
->setBody("Name: " . $name . "\r\nEmail: " . $email . "\r\nPhone: " . $number . "\r\nMessage: " . $comment)
;
echo "Resulttt!";
$result = $mailer->send($message);
$_SESSION['sent']=1;
//header("Location: contactus.php");
// }
echo "Hello world!";
?>
<br/><br/><br/>
<h1 style="text-align: center; color: #30ad07;" class="nocaps"> Thanks for your mail, we will get back to you shortly.. </h1>
<div style="text-align: center;">
<a href="index.html" class="btn btn-md btn-color text-center">Back to Homepage</a>
</div>
</body>
</html>