convert phpmailer code to use swiftmailer instead

Swift Mailer is a fantastic library for sending email with php. Discuss this library or ask any questions about it here.

Moderators: Chris Corbyn, General Moderators

Post Reply
gregtampa
Forum Newbie
Posts: 3
Joined: Thu Dec 15, 2011 12:46 pm

convert phpmailer code to use swiftmailer instead

Post by gregtampa »

current code is:
somewhere above im creating a class for phpmailer with code:

Code: Select all

require("PHPMailer/class.phpmailer.php");
then this is to send the mail which i need converted:

Code: Select all

$mail = new PHPMailer(true);
							//$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
							$mail->IsSMTP();                                        // set mailer to use SMTP
							$mail->Host = $smtp_host; // specify SMTP mail server
							$mail->Port = $smtp_port; // specify SMTP Port
							$mail->SMTPAuth = $smtp_auth; // turn on SMTP authentication
							$mail->Username = $smtp_user; //Full SMTP username
							$mail->Password =$smtp_pass; //SMTP password
							$mail->CharSet = $charset_encoding;
							//if($smtp_secure )
							  $mail->SMTPSecure =$smtp_secure;                 // sets the prefix to the servier
			
							
							$mail->From = $row[7];
							$mail->FromName = $row[6];
							//$mail->Sender =$error_ret_mail;
							$mail->AddAddress($Recipiant);
							$mail->AddReplyTo($mail->From, $mail->FromName);
							
							//$mail->WordWrap = 50; //optional, you can delete this line
							
							if($row[8]=="1") 
								$mail->IsHTML(true); //set email format to HTML
							
							$mail->Subject = $Subject;
							$mail->Body = $final_str;  //html body
							 $alt_content=$row[17];
							  $alt_content=str_replace("{UNSUBSCRIBE-LINK}","#",$alt_content);
						$alt_content=str_replace("{EMAIL}",$toemail,$alt_content);
						$alt_content=replaceExtraParams($mysql,$table_prefix,"$defaultname",$alt_content);
							$mail->AltBody=$alt_content;
I figured some of the syntax must be changed such as From is now setFrom when i need to use swiftmailer..
I can't figure out all the changes.. can someone assit?
Host = ?
Port = ?
etc:
gregtampa
Forum Newbie
Posts: 3
Joined: Thu Dec 15, 2011 12:46 pm

Re: convert phpmailer code to use swiftmailer instead

Post by gregtampa »

So this is about where im at now:

Code: Select all

//$mail = new PHPMailer(true);
							//$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
							//$mail->IsSMTP();                                        // set mailer to use SMTP
							//$mail->Host = $smtp_host; // specify SMTP mail server
							//$mail->Port = $smtp_port; // specify SMTP Port
							//$mail->SMTPAuth = $smtp_auth; // turn on SMTP authentication
							//$mail->Username = $smtp_user; //Full SMTP username
							//$mail->Password =$smtp_pass; //SMTP password
							//$mail->CharSet = $charset_encoding;
							//if($smtp_secure )
							 // $mail->SMTPSecure =$smtp_secure;                 // sets the prefix to the servier
							$mail = Swift_Mailer::newInstance($transport);
							//Create the Transport
							$transport = Swift_SmtpTransport::newInstance($smtp_host, $smtp_port)
							  ->setUsername($smtp_user)
							  ->setPassword($smtp_pass)
							  ;
							$mail->setFrom($row[7]);
							//$mail->FromName = $row[6];
							//$mail->Sender =$error_ret_mail;
							$mail->setTo($Recipiant);
							//$mail->AddReplyTo($mail->From, $mail->FromName);
							
							//$mail->WordWrap = 50; //optional, you can delete this line
							
							if($row[8]=="1") 
								$mail->IsHTML(true); //set email format to HTML
							
							$mail->setSubject = ($Subject);
							$mail->setBody = ($final_str, 'text/html');  //html body
							 $alt_content=$row[17];
							  $alt_content=str_replace("{UNSUBSCRIBE-LINK}","#",$alt_content);
						$alt_content=str_replace("{EMAIL}",$toemail,$alt_content);
						$alt_content=replaceExtraParams($mysql,$table_prefix,"$defaultname",$alt_content);
							$mail->addPart($alt_content, 'text/html');
							//$mail->AltBody = $content;  //plain text body
gregtampa
Forum Newbie
Posts: 3
Joined: Thu Dec 15, 2011 12:46 pm

Re: convert phpmailer code to use swiftmailer instead

Post by gregtampa »

Code: Select all

//$mail = new PHPMailer(true);
							//$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
							//$mail->IsSMTP();                                        // set mailer to use SMTP
							//$mail->Host = $smtp_host; // specify SMTP mail server
							//$mail->Port = $smtp_port; // specify SMTP Port
							//$mail->SMTPAuth = $smtp_auth; // turn on SMTP authentication
							//$mail->Username = $smtp_user; //Full SMTP username
							//$mail->Password =$smtp_pass; //SMTP password
							//$mail->CharSet = $charset_encoding;
							//if($smtp_secure )
							 // $mail->SMTPSecure =$smtp_secure;                 // sets the prefix to the servier
							$mail = Swift_Mailer::newInstance($transport);
							//Create the Transport
							$transport = Swift_SmtpTransport::newInstance($smtp_host, $smtp_port)
							  ->setUsername($smtp_user)
							  ->setPassword($smtp_pass)
							  ;
							$mail->setFrom($row[7]);
							//$mail->FromName = $row[6];
							//$mail->Sender =$error_ret_mail;
							$mail->setTo($Recipiant);
							//$mail->AddReplyTo($mail->From, $mail->FromName);
							
							//$mail->WordWrap = 50; //optional, you can delete this line
							
							if($row[8]=="1") 
								$mail->IsHTML(true); //set email format to HTML
							
							$mail->setSubject($Subject);
							$mail->setBody($final_str, 'text/html');  //html body
							 $alt_content=$row[17];
							  $alt_content=str_replace("{UNSUBSCRIBE-LINK}","#",$alt_content);
						$alt_content=str_replace("{EMAIL}",$toemail,$alt_content);
						$alt_content=replaceExtraParams($mysql,$table_prefix,"$defaultname",$alt_content);
							$mail->addPart($alt_content, 'text/plain');
							//$mail->AltBody = $content;  //plain text body
made some fixes.. i know there still errors cause the page comes up blank.
Post Reply