jacko310592 Posted November 24, 2009 Share Posted November 24, 2009 hey guys im having a problem with PHPMailer at the moment, im going to be using it to send a message from a contact form through my google email, the code i have so far is this: <?php include("../php/class.phpmailer.php"); include("../php/class.smtp.php"); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $body = $mail->getFile('contents.html'); $body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "mymail@googlemail.com"; // GMAIL username $mail->Password = "mypass"; // GMAIL password $mail->AddReplyTo("yourusername@gmail.com","First Last"); $mail->From = "name@yourdomain.com"; $mail->FromName = "First Last"; $mail->Subject = "PHPMailer Test Subject via gmail"; //$mail->Body = "Hi,<br>This is the HTML BODY<br>"; //HTML Body $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->WordWrap = 50; // set word wrap $mail->MsgHTML($body); $mail->AddAddress("whoto@otherdomain.com", "John Doe"); $mail->AddAttachment("images/phpmailer.gif"); // attachment $mail->IsHTML(true); // send as HTML if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message sent!"; } ?> but i recieve the following error: Warning: fopen(contents.html) [function.fopen]: failed to open stream: No such file or directory in E:\xampp\htdocs\website\php\phpmailer\class.phpmailer.php on line 1870 Mailer Error: SMTP Error: Could not connect to SMTP host. the file it seems to be having trouble with is the class.phpmailer.php, which is within the download for PHPMailer: http://sourceforge.net/projects/phpmailer/files/phpmailer%20for%20php4/PHPMailer%20v2.0.4%20for%20PHP4/PHPMailer_v2.0.4.zip/download a huge thanks to anyone who helps Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 24, 2009 Share Posted November 24, 2009 It can't locate "contact.html". Warning: fopen(contents.html) [function.fopen]: failed to open stream: No such file or directory Check your file paths. Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 24, 2009 Author Share Posted November 24, 2009 i change the php code abit: <?php //error_reporting(E_ALL); error_reporting(E_STRICT); date_default_timezone_set('Europe/London'); require_once('../php/phpmailer/class.phpmailer.php'); //include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded $mail = new PHPMailer(); $body = eregi_replace("[\]",'',$body); $mail->IsSMTP(); // telling the class to use SMTP $mail->Host = "mail.yourdomain.com"; // SMTP server $mail->SMTPDebug = 2; // enables SMTP debug information (for testing) // 1 = errors and messages // 2 = messages only $mail->SMTPAuth = true; // enable SMTP authentication $mail->SMTPSecure = "ssl"; // sets the prefix to the servier $mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server $mail->Port = 465; // set the SMTP port for the GMAIL server $mail->Username = "mymail@googlemail.com"; // GMAIL username $mail->Password = "pass"; // GMAIL password $mail->SetFrom($_POST['email'], $_POST['name']); $mail->AddReplyTo($_POST['email'], $_POST['name']); $mail->Subject = "Contact from visitor via your website"; $mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test $mail->MsgHTML($_POST['message']); $address = "mymail@googlemail.com"; //Person to send email to $mail->AddAddress($address, "Jacko"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { header('Location:./index.php'); exit; } ?> which works fine running from my PC, but when i upload it to my host i got the following error SMTP -> ERROR: Failed to connect to server: () SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. my host is running PHP v5, and the PHP Mailer is the verson for PHPv5, not the v4 one which i used in my 1st post can anyone think of whats going wrong? Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 24, 2009 Author Share Posted November 24, 2009 and on a second host i got this message: SMTP -> ERROR: Failed to connect to server: Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP? (40869804) SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host. Quote Link to comment Share on other sites More sharing options...
flyhoney Posted November 24, 2009 Share Posted November 24, 2009 Your host must be missing a PHP extension that you need. Quote Link to comment Share on other sites More sharing options...
bossman Posted November 24, 2009 Share Posted November 24, 2009 you might need to change some settings in your php.ini file. Or your not specifying your SMTP server correctly Quote Link to comment Share on other sites More sharing options...
jacko310592 Posted November 24, 2009 Author Share Posted November 24, 2009 could this part be the problem?: $mail->Host = "mail.yourdomain.com"; // SMTP server i arent sure whats needed to be placed there but it worked fine like that running from my PC. and with my host i cannot acess the PHP.ini, so id probs need 'ini_set' alternatives, thats if there is anything wrong with the .ini settings Quote Link to comment 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.