473,320 Members | 1,916 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Bugs with SMTP and PHPMailer

Hello Folks. I want to first appreciate for all the help that i have received here. I am pretty new to PHP and im trying to use PHP mailer for my SMYP settings. With the settings below, i tried to send the mail, but after a long time of loading, it just stops with a blank page. I set up and error report, that would let me know whether the message was sent or not, but i got no error message, just blank screen. I think its the STMP settings. Im supposed to put my ISP's Username and Password here.

Expand|Select|Wrap|Line Numbers
  1.     $mail->IsSMTP();
  2.     $mail->Host     = "mail.example.com";
  3.     $mail->Port     = 25;
  4.     $mail->SMTPAuth = false;
  5.     $mail->Username = "yourname@example.com";
  6.     $mail->Password = "yourpassword";
  7.  
I originally put my Gmail username and password up there.

This is the Full Code

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3.  
  4.     require_once("../zoomie_files/includes/PHPmailer/PHPMailerAutoload.php");
  5.  
  6.  
  7.     $to_name = "Test Mail";
  8.     $to = "timothyazubuikeh@gmail.com";
  9.     $subject = "Mail Test at ".strftime("%T", time());//Provides the time
  10.     $message ="This is a Test. Ignore the inbox";
  11.     $message = wordwrap($message, 70);
  12.     $from_name = "Timothy Azubuikeh";
  13.     $from = "admin@zoomie.com";
  14.  
  15.  
  16.     //PHP SMTP version default
  17.     $mail = new PHPMailer;
  18.  
  19.     $mail->IsSMTP();
  20.     $mail->Host     = "gmail.com";
  21.     $mail->Port     = 25;
  22.     $mail->SMTPAuth = false;
  23.     $mail->Username = "my_personal_email@gmail.com";
  24.     $mail->Password = "my_password";
  25.  
  26.     $mail->FromName = $from_name;
  27.     $mail->From     = $from;
  28.     $mail->AddAddress($to, $to_name);
  29.     $mail->Subject  = $subject;
  30.     $mail->Body     = $message;
  31.  
  32.  
  33.     if (!$mail->send())
  34.         {
  35.             echo "Mailer Error: " . $mail->ErrorInfo;
  36.         }
  37.     else 
  38.         {
  39.            echo "Message sent!";
  40.         }
  41.  
  42.  
  43. ?>
  44.  
  45.  
Please i need help with the SMTP settings or whatever the issue with the code is. Thanks
Apr 6 '15 #1
9 2517
Luuk
1,047 Expert 1GB
RTFM (read the fine manual)

it has:
Expand|Select|Wrap|Line Numbers
  1. $mail->SMTPAuth   = true;
it can be found here:
http://phpmailer.worxware.com/?pg=examplebgmail

oh, and use the toolbar to insert '[CODE/]' tags....
Apr 6 '15 #2
Thanks Luuk, before i try it out, do you mean that the email and password info i put there were correct?? Thanks.
Apr 6 '15 #3
Thanks Luuk. I change the false to true in
Expand|Select|Wrap|Line Numbers
  1. $mail->SMTPAuth   = true;
. It still did the same thing it did when SMTPAuth was false. (loaded for a long time and came up with a blank page).

What do you think is the problem???
Apr 6 '15 #4
Luuk
1,047 Expert 1GB
The problem should be noted somewhere in your logfiles.....

If I want to sent an email from PHP I would use:
http://php.net/manual/en/function.mail.php

And not a library which is more than 4 years old, meant to send mail by PHP, with a now-working sample form

But documentation is here:
http://www.worxware.com/kbn/?category_id=23
Apr 6 '15 #5
Thanks Luuk. The article you gave me is about just about the PHP mail() function.

When you talk about log files and 'library which is more than 4 years old', honestly, i dont really understand would be grateful if you explained better. Im a novice.


I ran this code

Expand|Select|Wrap|Line Numbers
  1.  
  2. <?php 
  3.  
  4. $inis = Array('SMTP', 'smtp_port', 'sendmail_path');// from not important 
  5. foreach($inis as $key=>$val){ 
  6.   echo "\t<p>{$val}</p>\n<code>\n"; 
  7.   var_dump(ini_get($val)); 
  8.   echo "</code>\n"; 
  9. };
  10.  
And its output was

SMTP

string(9) "localhost"
smtp_port

string(2) "25"
sendmail_path

bool(false)

I also ran this code to test the STMP class to see whether a connection can be made to the server

Expand|Select|Wrap|Line Numbers
  1. date_default_timezone_set('Etc/UTC'); 
  2.  
  3. require ("../zoomie_files/includes/PHPmailer/PHPMailerAutoload.php"); 
  4.  
  5. //Create a new SMTP instance 
  6. $smtp = new SMTP; 
  7.  
  8. //Enable connection-level debug output 
  9. $smtp->do_debug = SMTP::DEBUG_CONNECTION; 
  10.  
  11. try { 
  12. //Connect to an SMTP server 
  13.     if ($smtp->connect('www.gmail.com', 25)) { 
  14.         //Say hello 
  15.         if ($smtp->hello('localhost')) { //Put your host name in here 
  16.             //Authenticate 
  17.             if ($smtp->authenticate('my_personal_email@gmail.com', 'my_pasword')) { 
  18.                 echo "Connected ok!"; 
  19.             } else { 
  20.                 throw new Exception('Authentication failed: ' . $smtp->getLastReply()); 
  21.             } 
  22.         } else { 
  23.             throw new Exception('HELO failed: '. $smtp->getLastReply()); 
  24.         } 
  25.     } else { 
  26.         throw new Exception('Connect failed'); 
  27.     } 
  28. } catch (Exception $e) { 
  29.     echo 'SMTP error: '. $e->getMessage(), "\n"; 
  30. //Whatever happened, close the connection. 
  31. $smtp->quit(true);  
  32.  
And its output was this.

2015-04-07 20:34:50 Connection: opening to www.gmail.com:25, t=30, opt=array ( ) 2015-04-07 20:34:50 Connection: opened

But the script still does as before,(blank page). Hasnt a connection to a server been made? What do you think is the problem? Thanks Luuk for your help. Thanks.
Apr 7 '15 #6
Luuk
1,047 Expert 1GB
I cannot find the file you included on line#3 ("PHPMailerAutoload.php"), I does not exist in PHPMailer, at least not in the version I downloaded from: http://sourceforge.net/projects/phpmailer/

Do I have an old, or wrong, version?


What I mean about 'more than 4 years old' is the dates on the site: http://www.worxware.com/kbn/?category_id=23

Back to the topic, you seem to have the need to send email from PHP.
1) What kind of email do you want to send?
a) just text
b) HTML
c) text + attachment
d) HTML + attachment

The basic PHP mail function is able to do option a) very easy, and every next option is only slightly more complicated.
Apr 8 '15 #7
Thanks Luuk, been quite a while, i have been really busy. I opted against using PHPmailer because i heard that it is always meddled with complications. A friend suggested another third party email system. sendgrid.com . I signed up,looked up the documentation and looked at their integration with Open Source apps(PHP in this case). I worked with this code

Expand|Select|Wrap|Line Numbers
  1. require_once("../zoomie_files/includes/sendgrid/smtpapi-php.php");
  2.  
  3.  use Smtpapi\Header;
  4.  
  5. $transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
  6. $transport->setUsername('sendgrid_username');
  7. $transport->setPassword('sendgrid_password');
  8.  
  9. $mailer = \Swift_Mailer::newInstance($transport);
  10.  
  11. $message = new \Swift_Message();
  12. $message->setTos(array('send_to@gmail.com'));
  13. $message->setFrom('sent_from@gmail.com');
  14. $message->setSubject('Hello');
  15. $message->setBody('%how% are you doing?');
  16.  
  17. $header = new Header();
  18. $header->addSubstitution('%how%', array('Owl'));
  19.  
  20. $message_headers = $message->getHeaders();
  21. $message_headers->addTextHeader(HEADER::NAME, $header->jsonString());
  22.  
  23. try {
  24.     $response = $mailer->send($message);
  25.     print_r($response);
  26. } catch(\Swift_TransportException $e) {
  27.     print_r('Bad username / password');
  28. }
  29.  
  30.  

It gave me some errors wherever the "\" appeared. That is not a filepath seperator ryt? For windows, its "/". Its triggering errors. Please what does the "\" mean?

This is the first error statement

"Parse error: syntax error, unexpected T_STRING, expecting T_CONSTANT_ENCAPSED_STRING or '(' in C:\wamp\www\btb_sandbox\sendemail7.php on line 7"

In

Expand|Select|Wrap|Line Numbers
  1.  
  2. use Smtpapi\Header; //There is actually a php file titled 'Header' in a folder named 'Smtpapi'.
  3. //Is this an attempt to locate the file 'Header'?
  4. These are other cases where the "\" appeared. 
  5. *** $transport = \Swift_SmtpTransport::newInstance('smtp.sendgrid.net', 587);
  6. **  $mailer = \Swift_Mailer::newInstance($transport);
  7. *   $message = new \Swift_Message();
  8.  
  9.  

What do you think is wrong? What is the '\' sign for? Thanks for your help, i really appreciate. Thanks
Apr 20 '15 #8
Luuk
1,047 Expert 1GB
The '\' is for something with namespaces see:
http://php.net/manual/en/language.na...s.fallback.php

My knowledge about that is limited too ;)
(but Google is my friend....)

You need PHP version >= 5.3.0 for this to work.
Apr 20 '15 #9
Thanks Luuk. I upgraded to 5.5 and its giving me this error.

Fatal error: Class 'Swift_SmtpTransport' not found in C:\wamp\www\btb_sandbox\sendemail8.php on line 8

What do you think is the problem this time around? Thanks Luuk, you have been helpful.
Apr 26 '15 #10

Sign in to post your reply or Sign up for a free account.

Similar topics

7
by: oopsbabies | last post by:
Hello everyone, I am using Apache 1.3.33 as the web server and PHP version 4.3.10. My machine is using Windows XP 2002 professional edition which comes with a Windows firewall. I am using McAfee...
7
dlite922
by: dlite922 | last post by:
I can't seem to get it working with my smtp server. I can send the email through the command line like so: 220 localhost.localdomain ESMTP Sendmail 8.13.8/8.13.8; Wed, 6 Aug 2008 18:44:29...
2
mikek12004
by: mikek12004 | last post by:
Before posting here I google it and saw ablut 30 pages for a solution so I pretty much excluded the obvious things. The code is <?php //now to send the mails to seller...
5
vivekgs2007
by: vivekgs2007 | last post by:
HI to all, I downloaded the Php Mailer Function, I embedded it to my Feedback page, It is not giving any error, But the mail is not going, I don't no where i gone wrong...Please help me...
2
by: Rekha Kumaran | last post by:
I downloaded phpmailer-0.9.zip. I added below 2 lines in php.ini. include_path="/home/rose/phpmailer/phpmailer.inc.php" include_path="/home/rose/phpmailer/smtp.inc.php" If i run the below...
0
by: harini0590 | last post by:
<?php //this is a path to PHP mailer class you have dowloaded include("class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); // set mailer to use SMTP
1
by: shyqyri | last post by:
Hello, i have one website in php, but i have one module to send newslater to my subscribe. i have VPS server for unlimited email sending. but i have one problem, i have 24.000 email in my database...
14
by: afroz ahmad | last post by:
i am trying to send multiple mail using phpmailer. I have a problem. When i click send button, just zxc@gmail.com and abc@yahoo.com receives the message. How to change it? I'm use Gmail SMTP send...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.