1

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>
  • Look for error messages. Maybe in the web server logs or force PHP to show any errors it may be hiding. http://stackoverflow.com/questions/5438060/showing-all-errors-and-warnings – Marc Compte Feb 07 '17 at 09:02
  • Swift_TransportException: Connection could not be established with host smtp.gmail.com [A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. #10060] in C:\wamp64\www\Qaswaa\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php on line 269 @MarcCompte –  Feb 07 '17 at 13:29
  • Fatal error: Uncaught exception 'Swift_TransportException' with message ' in C:\wamp64\www\Qaswaa\swiftmailer\lib\classes\Swift\Transport\StreamBuffer.php on line 269... These are the errors that I get –  Feb 07 '17 at 13:31
  • Check http://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page and http://stackoverflow.com/questions/3478906/using-phps-swiftmailer-with-gmail. There are various answers, some may be outdated. If you still don't find the solution, now that you know more try changing the title of this post to a more descriptive one, and paste the full error in the body. Include gmail as a tag also. Maybe this way you attract a more illustrated crowd. – Marc Compte Feb 07 '17 at 17:22

0 Answers0