PHPmailer for sending email problem~ Help!

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nickchou
Forum Newbie
Posts: 6
Joined: Sat Aug 25, 2007 1:53 pm

PHPmailer for sending email problem~ Help!

Post by nickchou »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


Hello guys.

      I'm facing a problem 4 using PHPmailer to send email.  

error:

Message was not sent 
Mailer Error: The following From address failed: epaymanager@163.com

My code:

Code: Select all

<?php

ini_set("include_path", "C:\xampp\htdocs\bsp"); 

require("class.phpmailer.php"); 
require("class.smtp.php"); 
require("language/phpmailer.lang-en.php"); 
$mail = new PHPMailer();
$mail->IsSMTP(); // send via SMTP
$mail->Host = "smtp.163.com"; // SMTP servers
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->Username = "epaymanager@163.com"; // SMTP username
$mail->Password = "*****"; // SMTP password
 
$mail->From = "epaymanager@163.com";
$mail->FromName = "My Name";
$mail->AddAddress("epaymanager@163.com","Josh Adams");
//$mail->AddAddress("to2@email.com"); // optional name
 
//$mail->AddReplyTo("jyu@aemtechnology.com","AEM");
 
$mail->WordWrap = 50; // set word wrap
 
$mail->IsHTML(true); // send as HTML
$mail->Subject = "testing email";
$mail->Body = "This is the <b>HTML body</b>";
//$mail->AltBody = "This is the text-only body";
 
if(!$mail->Send())
{
    echo "Message was not sent <p>";
    echo "Mailer Error: " . $mail->ErrorInfo;
    exit;
}
 
echo "Message has been sent";
?>

Can someone help me? Thanks a lot!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
Chris Corbyn
Breakbeat Nuttzer
Posts: 13098
Joined: Wed Mar 24, 2004 7:57 am
Location: Melbourne, Australia

Post by Chris Corbyn »

Try using Swift Mailer and see if you get a better error.

http://www.swiftmailer.org/

It wouldn't amaze me if the PHPMailer code is disallowing the domain 163.com based on a faulty regular expression. It may be a relaying problem but I'd expect a better error message if that's the case.
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

remove auth

Post by yacahuma »

comment this lines
//$mail->SMTPAuth = true; // turn on SMTP authentication
//$mail->Username = "epaymanager@163.com"; // SMTP username
//$mail->Password = "*****"; // SMTP password

an change host to localhot if you are running on the same machine
$mail->Host = "localhost";


Remember to use a valid email in the from. That should work. Try it an let us know.
nickchou
Forum Newbie
Posts: 6
Joined: Sat Aug 25, 2007 1:53 pm

Post by nickchou »

d11wtq wrote:Try using Swift Mailer and see if you get a better error.

http://www.swiftmailer.org/

It wouldn't amaze me if the PHPMailer code is disallowing the domain 163.com based on a faulty regular expression. It may be a relaying problem but I'd expect a better error message if that's the case.

The problem is I also changed other domains, but I got same error.
yacahuma wrote:comment this lines
//$mail->SMTPAuth = true; // turn on SMTP authentication
//$mail->Username = "epaymanager@163.com"; // SMTP username
//$mail->Password = "*****"; // SMTP password

an change host to localhot if you are running on the same machine
$mail->Host = "localhost";


Remember to use a valid email in the from. That should work. Try it an let us know.
I'm so sorry that it didn't work.

I guess it is because there's no SMTP server in my laptop.
And the email I filled in is valid.

the error also came out:

Warning: fputs(): supplied argument is not a valid stream resource in C:\xampp\htdocs\bsp\class.smtp.php on line 146

Warning: fgets(): supplied argument is not a valid stream resource in C:\xampp\htdocs\bsp\class.smtp.php on line 1024
Message was not sent
Mailer Error: The following From address failed: epay_manager@sina.com
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

It is supposed to run on the server

Post by yacahuma »

Is not going to run on your laptop. It is suppose to run on the actual server. Can you move it to the server an try again.
nickchou
Forum Newbie
Posts: 6
Joined: Sat Aug 25, 2007 1:53 pm

Re: It is supposed to run on the server

Post by nickchou »

yacahuma wrote:Is not going to run on your laptop. It is suppose to run on the actual server. Can you move it to the server an try again.
I'm so sorry. This is my project 4 assignment.
I need to demo to my lecturer... :oops:
User avatar
yacahuma
Forum Regular
Posts: 870
Joined: Sun Jul 01, 2007 7:11 am

install an smtp server

Post by yacahuma »

You need something in your machine to send the email. I dont know if swift mailer can send it directly.

I dont know what configuration you have but you can try to install your own little smtp server

in windows there is one called
ArGoSoft Mail Server Freeware 1.8.8.8 you can get it at downloads.com

i think you can also enable something in iis to do it. But I will try the argosoft first.
nickchou
Forum Newbie
Posts: 6
Joined: Sat Aug 25, 2007 1:53 pm

Re: install an smtp server

Post by nickchou »

yacahuma wrote:You need something in your machine to send the email. I dont know if swift mailer can send it directly.

I dont know what configuration you have but you can try to install your own little smtp server

in windows there is one called
ArGoSoft Mail Server Freeware 1.8.8.8 you can get it at downloads.com

i think you can also enable something in iis to do it. But I will try the argosoft first.
Hi buddy~ I've installed the server with the version of 1.8.9.1
But when I tried to start the server, I got a problem:

Error starting SMTP server:[10048] Address already in use

Error starting Web server:[10048] Address already in use
nickchou
Forum Newbie
Posts: 6
Joined: Sat Aug 25, 2007 1:53 pm

Post by nickchou »

Thanks man, I got that error because of default SMTP of windows. I closed it, and it is ok now.

Now, I have this server. So how can I use the code?

Thanks again..
Steve Mellor
Forum Commoner
Posts: 49
Joined: Thu Aug 02, 2007 8:18 am

Post by Steve Mellor »

Just thought it might be useful if you had a working script to check everything against.

This runs perfectly from my machine which is using Wampserver:

Code: Select all

require("phpmailer/class.phpmailer.php");
		$mail = new PHPMailer();
		$mail->IsSMTP(); // telling the class to use SMTP
		$mail->Host = "mail.mellorweb.co.uk"; // SMTP server
		$mail->Username="website@mellorweb.co.uk";
		$mail->Password="[ Of course I'm not putting the password in here  ]";
		$mail->SMTPAuth=true;
		$mail->From = "From Email";
		$mail->FromName = "From Name";
		$mail->AddAddress("steve@mellorweb.co.uk");
		$mail->Subject = "Subject";
		$mail->Body = "Hello, this is a message form your website."
All it really relies on is getting the right SMTP settings. Of course there are some SMTP hosts that don't like you using their resources on your website so that might be where you're getting the problem. But the code is sound and PHPMailer is a good system once you've got it working.
Post Reply