prash91 Posted October 3, 2014 Share Posted October 3, 2014 Hi I am trying to send email through following php code to may gmail account but it givrs me SMTP Error: Could not connect to SMTP host. ******************************************************************************************************************************************************* <?phpif(isset($_POST['submit'])){ $message='Full Name: '.$_POST['fullname'].'<br />Subject: '.$_POST['subject'].'<br />Phone: '.$_POST['phone'].'<br />Email: '.$_POST['emailid'].'<br />Comments: '.$_POST['comments'].''; require "phpmailer/class.phpmailer.php"; //include phpmailer class // Instantiate Class $mail = new PHPMailer(); // Set up SMTP $mail->IsSMTP(); // Sets up a SMTP connection $mail->SMTPAuth = true; // Connection with the SMTP does require authorization $mail->SMTPSecure = "ssl"; // Connect using a TLS connection $mail->Host = "smtp.gmail.com"; //Gmail SMTP server address $mail->Port = 465; //Gmail SMTP port $mail->Encoding = '7bit'; // Authentication $mail->Username = "myemail@gmail.com"; // Your full Gmail address $mail->Password = "mypassword"; // Your Gmail password // Compose $mail->SetFrom($_POST['emailid'], $_POST['fullname']); $mail->AddReplyTo($_POST['emailid'], $_POST['fullname']); $mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required) $mail->MsgHTML($message); // Send To $mail->AddAddress("myemail@gmail.com", "Recipient Name"); // Where to send it - Recipient $result = $mail->Send(); // Send! $message = $result ? 'Successfully Sent!' : 'Sending Failed!'; unset($mail); }?><html><head> <title>Contact Form</title></head><body> <div style="margin: 100px auto 0;width: 300px;"> <h3>Contact Form</h3> <form name="form1" id="form1" action="" method="post"> <fieldset> <input type="text" name="fullname" placeholder="Full Name" /> <br /> <input type="text" name="subject" placeholder="Subject" /> <br /> <input type="text" name="phone" placeholder="Phone" /> <br /> <input type="text" name="emailid" placeholder="Email" /> <br /> <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea> <br /> <input type="submit" name="submit" value="Send" /> </fieldset> </form> <p><?php if(!empty($message)) echo $message; ?></p> </div> </body></html> Quote Link to comment https://forums.phpfreaks.com/topic/291422-smtp-error-could-not-connect-to-smtp-host/ Share on other sites More sharing options...
prash91 Posted October 14, 2014 Author Share Posted October 14, 2014 73 views 0 reply Quote Link to comment https://forums.phpfreaks.com/topic/291422-smtp-error-could-not-connect-to-smtp-host/#findComment-1493545 Share on other sites More sharing options...
CroNiX Posted October 14, 2014 Share Posted October 14, 2014 (edited) Maybe it's just the formatting, but most of that code looks really broken due to things showing up on the next line where they shouldn't be. Stuff like: class // Instantiate Also, try setting more of the parameters like here: http://ctrlq.org/code/19589-send-mail-php Edited October 14, 2014 by CroNiX Quote Link to comment https://forums.phpfreaks.com/topic/291422-smtp-error-could-not-connect-to-smtp-host/#findComment-1493546 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.