cadi2108
cadi2108

Reputation: 1280

Empty page after sending mail with phpMailer

I'm trying to send mail using phpMailer. It's my code:

<?php
  require_once('phpmailer/class.phpmailer.php');
  $mail = new PHPMailer(true);

  $mail->PluginDir = "phpmailer/";
  $mail->IsSMTP();
  $mail->SMTPAuth = true; // enable SMTP authentication
  $mail->SMTPSecure = "ssl"; // sets the prefix to the servier
  $mail->Host = "smtp.gmail.com";
  $mail->Port = 465;
  $mail->Username = "[email protected]";
  $mail->Password = "xxxxx";

  $mail->SetFrom('[email protected]', 'Nasze imie i nazwisko');

  $mail->AddAddress("[email protected]"); // ADRESAT

  $mail->Subject = 'Test message';

  // w zmienną $text_body wpisujemy treść maila
  $text_body = "Hello, \n\n";
  $text_body .= "Sending succesfully, \n";
  $text_body .= "PHPMailer";

  $mail->Body = $text_body;

  if(!$mail->Send())
    echo "There has been a mail error <br>";
  echo $mail->ErrorInfo."<br>";

  // Clear all addresses and attachments
  $mail->ClearAddresses();
  $mail->ClearAttachments();
  echo "mail sent <br>";
?>

Mail didn't send and in browser i have empty page, without message. What is here wrong?

Best regards, Dagna

Upvotes: 1

Views: 5031

Answers (1)

Sarfraz
Sarfraz

Reputation: 382806

Mail didn't send and in browser i have empty page, without message. What is here wrong?

Try setting error checking on (for development only):

ini_set('display_errors',  true);
error_reporting(1);

Put above two lines on top of your page. This should give you some message now eg what error is coming up exactly.

update

I modified the class.smtp.php file's Connect function like this to get it working for myself:

public function Connect($host, $port = 0, $tval = 30) {

  $host = "ssl://smtp.gmail.com";
  $port = 465;

  // other code

And my email sending code was which works is;

require("PHPMailer_v5.1/class.phpmailer.php");

$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "[email protected]"; // SMTP username
$mail->Password = "xxxxxxxxx"; // SMTP password
$webmaster_email = "[email protected]"; //Reply to this email ID
$email = "[email protected]"; // Recipients email ID
$name = "Sarfraz"; // Recipient's name
$mail->From = $webmaster_email;
$mail->FromName = "Local Mail from Sarfraz";
$mail->AddAddress($email, $name);
$mail->AddReplyTo($webmaster_email,"Webmaster");
$mail->WordWrap = 50; // set word wrap
$mail->IsHTML(true); // send as HTML
$mail->Subject = "I am a local mail !";
$mail->Body = "Hey What's up? Have fun :)"; //HTML Body

if(!$mail->Send())
{
  echo "Mailer Error: " . $mail->ErrorInfo;
}
else
{
  echo "Message has been sent";
}

Upvotes: 4

Related Questions