using class.phpmailer.php to send mail

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
chungln
Forum Newbie
Posts: 2
Joined: Fri Sep 15, 2006 9:32 pm

using class.phpmailer.php to send mail

Post by chungln »

hawleyjr | 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]


Hi there,
I'm using class.phpmailer.php to send mail and i have some following problems:

- when used smtp.gmail.com =>  must starttsl ???
- when used smtp.mail.yahoo.com => need authorization
- orthers smtp without SSL is ok. send mail ok but the reply-to do not work and work only on localhost.
when i upload the code to host i can not send mail anymore the problem is : can not connect to host 

any suggestion ?

my code like this ..

Code: Select all

if(!empty($_GET['mode'])){
	require("class.phpmailer.php");	
	$mode=$_GET['mode'];	
	$mail = new PHPMailer();		
	$mail->IsSMTP();                                      // set mailer to use SMTP
	$mail->Host = "smtp.gmail.com";  // specify main and backup server	
	$mail->Port= 587;
	$mail->SMTPAuth = true;     // turn on SMTP authentication
	$mail->Username = "myemail@gmail.com";  // SMTP username
	$mail->Password = "mypass"; // SMTP password
	
	$mail->IsSMTP();   // set mailer to use SMTP
	
	if($mode==1){
	
		$name =	$_GET['name_txt'];
		$email = $_GET['email_txt'];
		$company = $_GET['company_txt'];
		$phone = $_GET['phone_txt'];
		$content = $_GET['content_txt'];
		$body = "Fullname : " . $name . "<br>";
		$body.= "Email : " . $email . "<br>";
		$body.= "Company : ". $company . "<br>";
		$body.= "Phone : ". $phone . "<br>";
		$body.= "Message : ". $content . "<br>";			
		
	}elseif ($mode==2){
		
		$firstname =	$_GET['firstname_txt'];
		$lastname =	$_GET['lastname_txt'];
		$name= $firstname . ", " . $lastname;
		$email = $_GET['email_txt'];
		$city = $_GET['city_txt'];
		$phone = $_GET['phone_txt'];
		$content = $_GET['content_txt'];
		$body = "Firstname : " . $firstname . "<br>";
		$body.= "Lastname : " . $lastname . "<br>";
		$body.= "Email : " . $email . "<br>";
		$body.= "City/State : ". $city . "<br>";
		$body.= "Phone : ". $phone . "<br>";
		$body.= "Message : ". $content . "<br>";
		$fileName="";
		if(!empty($_GET['attach_f'])) $fileName=$_GET['attach_f'];
		if($fileName!="")	$mail->AddAttachment($fileName);	
	}	
	
	$mail->From = "myemail@gmail.com";	
	$mail->FromName = $name;
	$mail->AddAddress("toguess@mail.com", "LSC");
	$mail->AddReplyTo("myemail@gmail.com", "Information");
	$mail->WordWrap = 50;                                 // set word wrap to 50 characters
	//$mail->AddAttachment("cv.doc");         // add attachments
	//$mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
	$mail->IsHTML(true);                                  // set email format to HTML
	
	$mail->Subject = "From Customers ...";
	$mail->Body    = $body;
	//$mail->AltBody = $altBody;
	$result="";
	if(!$mail->Send()){
		$mail->Host = "smtp.mail.yahoo.com";  // specify main and backup server	
		$mail->Port= 587;		
		$mail->Username = "myemail@yahoo.com";  // SMTP username
		$mail->Password = "mypass"; // SMTP password
		$mail->AddReplyTo("myemail@yahoo.com", "Information");
		if(!$mail->Send()){
			$result= "Message could not be sent. <p> Error: " . $mail->ErrorInfo . " <p>";
			echo $result;
			exit;
		}	
	}			
	$mail->ClearAddresses();
	$mail->ClearAttachments();
	$mail->FromName = "LSC";
	$mail->AddAddress($email, $name);
	$mail->Subject = "the subject!!!";
	$body=" the body";
	$mail->Body = $body;	
	if(!$mail->Send()){
		$mail->Host = "smtp.mail.yahoo.com";  // specify main and backup server	
		$mail->Port= 587;		
		$mail->Username = "myemail@yahoo.com";  // SMTP username
		$mail->Password = "mypass"; // SMTP password
		$mail->AddReplyTo("myemail@yahoo.com", "Information");
		if(!$mail->Send()){
			$result= "Message could not be sent. <p> Error: " . $mail->ErrorInfo . " <p>";
			echo $result;
			exit;
		}		
	}	
	if($result=="") $result= " the result";
	echo $result;
}
hawleyjr | 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
Benjamin
Site Administrator
Posts: 6935
Joined: Sun May 19, 2002 10:24 pm

Post by Benjamin »

Just use d11's swiftmailer. It has the features you require along with some great examples.
chungln
Forum Newbie
Posts: 2
Joined: Fri Sep 15, 2006 9:32 pm

Post by chungln »

thx you, but my code run well now..
Post Reply