Best Atoum code snippet using mailer.setReplyTo
init.engine.php
Source:init.engine.php
...30 31 # Create a message32 $message->setEncoder(Swift_Encoding::getBase64Encoding());33 if($email_reply_to != null){34 $message->setReplyTo(array($email_reply_to => $email_reply_to_name));35 }36 $message->setCharset('utf-8');37 $message->setPriority(1);38 $message->setFrom(array($config['admin_email'] => $config['site_title']));39 # Receivers40 $message->setTo(array($email_to => $email_to_name));41 $message->setSubject($email_subject);42 if($config['email_template']==0){43 $ContentType = "text/html";44 }45 else{46 $ContentType = "text/plain";47 }48 $message->setBody($email_body,$ContentType);49 # Send Message50 if(!$mailer->send($message)){51 $sendingErrors = 'Messages could not be sent!';52 $sendPos = false;53 }else{54 $sendingErrors = 'Sent successfully';55 $sendPos = true;56 }57 return $sendPos;58}59# ********************************************************************************************************************************60else if($config['email_type'] == 'mail'){ # PHPMail61 $transport = Swift_MailTransport::newInstance();62 63 # Create Mailer64 $mailer = Swift_Mailer::newInstance($transport);65 $message = Swift_Message::newInstance();66 # Create a message67 $message->setEncoder(Swift_Encoding::getBase64Encoding());68 if($email_reply_to != null){69 $message->setReplyTo(array($email_reply_to => $email_reply_to_name));70 }71 $message->setCharset('utf-8');72 $message->setPriority(1);73 $message->setFrom(array($config['admin_email'] => $config['site_title']));74 # Receivers75 $message->setTo(array($email_to => $email_to_name));76 $message->setSubject($email_subject);77 if($config['email_template']==0){78 $ContentType = "text/html";79 }80 else{81 $ContentType = "text/plain";82 }83 $message->setBody($email_body,$ContentType);84 # Send Message85 if(!$mailer->send($message)){86 $sendingErrors = 'Messages could not be sent!';87 $sendPos = false;88 }else{89 $sendingErrors = 'Sent successfully';90 $sendPos = true;91 }92}93# ********************************************************************************************************************************94else if($config['email_type'] == 'aws'){ # Amazon SES95 $transport = Swift_SmtpTransport::newInstance();96 $transport->setHost($config['aws_host']);97 $transport->setPort(465);98 $transport->setUsername($config['aws_access_key']);99 $transport->setPassword($config['aws_secret_key']);100 $transport->setEncryption('tls');101 102 # Create Mailer103 $mailer = Swift_Mailer::newInstance($transport);104 $message = Swift_Message::newInstance();105 # Create a message106 $message->setEncoder(Swift_Encoding::getBase64Encoding());107 if($email_reply_to != null){108 $message->setReplyTo(array($email_reply_to => $email_reply_to_name));109 }110 $message->setCharset('utf-8');111 $message->setPriority(1);112 $message->setFrom(array($config['admin_email'] => $config['site_title']));113 # Receivers114 $message->setTo(array($email_to => $email_to_name));115 $message->setSubject($email_subject);116 if($config['email_template']==0){117 $ContentType = "text/html";118 }119 else{120 $ContentType = "text/plain";121 }122 $message->setBody($email_body,$ContentType);123 # Send Message124 if(!$mailer->send($message)){125 $sendingErrors = 'Messages could not be sent!';126 $sendPos = false;127 }else{128 $sendingErrors = 'Sent successfully';129 $sendPos = true;130 }131}132# ********************************************************************************************************************************133else if($config['email_type'] == 'mandrill'){ # Mandrill134 $transport = Swift_SmtpTransport::newInstance();135 $transport->setHost('smtp.mandrillapp.com');136 $transport->setPort(587);137 $transport->setUsername($config['mandrill_user']);138 $transport->setPassword($config['mandrill_key']);139 $transport->setEncryption('tls');140 141 # Create Mailer142 $mailer = Swift_Mailer::newInstance($transport);143 $message = Swift_Message::newInstance();144 # Create a message145 $message->setEncoder(Swift_Encoding::getBase64Encoding());146 if($email_reply_to != null){147 $message->setReplyTo(array($email_reply_to => $email_reply_to_name));148 }149 $message->setCharset('utf-8');150 $message->setPriority(1);151 $message->setFrom(array($config['admin_email'] => $config['site_title']));152 # Receivers153 $message->setTo(array($email_to => $email_to_name));154 $message->setSubject($email_subject);155 if($config['email_template']==0){156 $ContentType = "text/html";157 }158 else{159 $ContentType = "text/plain";160 }161 $message->setBody($email_body,$ContentType);162 # Send Message163 if(!$mailer->send($message)){164 $sendingErrors = 'Messages could not be sent!';165 $sendPos = false;166 }else{167 $sendingErrors = 'Sent successfully';168 $sendPos = true;169 }170}171# ********************************************************************************************************************************172else if($config['email_type'] == 'sendgrid'){ # SendGrid173 $transport = Swift_SmtpTransport::newInstance();174 $transport->setHost('smtp.sendgrid.net');175 $transport->setPort(587);176 $transport->setUsername($config['sendgrid_user']);177 $transport->setPassword($config['sendgrid_pass']);178 $transport->setEncryption('tls');179 180 # Create Mailer181 $mailer = Swift_Mailer::newInstance($transport);182 $message = Swift_Message::newInstance();183 # Create a message184 $message->setEncoder(Swift_Encoding::getBase64Encoding());185 if($email_reply_to != null){186 $message->setReplyTo(array($email_reply_to => $email_reply_to_name));187 }188 $message->setCharset('utf-8');189 $message->setPriority(1);190 $message->setFrom(array($config['admin_email'] => $config['site_title']));191 # Receivers192 $message->setTo(array($email_to => $email_to_name));193 $message->setSubject($email_subject);194 if($config['email_template']==0){195 $ContentType = "text/html";196 }197 else{198 $ContentType = "text/plain";199 }200 $message->setBody($email_body,$ContentType);...
MailerTest.php
Source:MailerTest.php
...15 protected $mailer;16 public function setUp() {17 parent::setUp();18 $this->mockMessage = $this->getMockBuilder('Neos\SwiftMailer\Message')19 ->setMethods(array('setFrom', 'setTo', 'addCc', 'setBody', 'send', 'setSubject', 'getTo', 'getSubject', 'getRecipientIdentifier', 'setReplyTo'))20 ->getMock();21 $this->mailer = new \Networkteam\Util\Mail\Mailer();22 $this->mailer->setMessage($this->mockMessage);23 $logger = $this->getMock('Networkteam\Util\Log\MailerLoggerInterface');24 $this->inject($this->mailer, 'logger', $logger);25 }26 /**27 * @@test28 */29 public function mailerUsesAddCcForAddingRecipients() {30 $this->mockMessage->expects($this->exactly(2))31 ->method('addCc');32 $this->mockMessage->expects($this->exactly(1))33 ->method('setReplyTo')34 ->with($this->equalTo('my-reply@example.com'));35 $mailMessage = new MailMessage();36 $mailMessage->setRecipients(array(37 'test1@example.com',38 'test2@example.com',39 'test3@example.com',40 ));41 $mailMessage->setReplyTo('my-reply@example.com');42 $this->mailer->send($mailMessage);43 }44 /**45 * @@test46 */47 public function mailerSkipsReplyToIfEmpty() {48 $this->mockMessage->expects($this->never())49 ->method('setReplyTo');50 $mailMessage = new MailMessage();51 $mailMessage->setRecipients(array(52 'test1@example.com'53 ));54 $this->mailer->send($mailMessage);55 }56}...
Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Execute automation tests with setReplyTo on a cloud-based Grid of 3000+ real browsers and operating systems for both web and mobile applications.
Test now for FreeGet 100 minutes of automation test minutes FREE!!