Jump to content

PHPMailer, Help Please


jacko310592

Recommended Posts

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

Link to comment
Share on other sites

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?

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.