I have built a website which has the contact form and sends a mail with the users "Email, Name, Number and Message". I have used Swift mailer for this and below is the code. It echoes "Hello World" and "Result", but doesn't send any mail or display the Thank you message. It would be of great help if someone could help me here with this.
<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>