This topic is locked
[SOLVED]

 smtp email with attachment

3/2/2015 8:03:35 AM
PHPRunner General questions
M
monoofy author

Dears,
Hope you are all OK.

I'm using the after add event to send an email with data inclusing the attached file.

I use authentication to send the email.

Below is my current event, I want your help to add the attachment part.

Thanks in advance.



// After record added

function AfterAdd(&$values,&$keys,$inline)

{

// Place event code here.

// Use "Add Action" button to add code snippets.
require_once "Mail.php";

$from = "XXXXXXX <xxxxx>";

$to = "XXXXXXX <xxxxx>";

$subject = "SLM - Ticket No. ".$values["tkt_id"]." Added";

$body = "Dear Mahmoud,"."\n"."Kindly be noted that ticket # ".$values["tkt_id"]." - is now added to the system"."\n"."\n"."Best Regards,"."\n"."Service Level Management System";

$host = "xxxxx";

$username = "xxxxx";

$password = "xxxxx";

$headers = array ('From' => $from, 'To' => $to, 'Subject' => $subject);

$smtp = Mail::factory('smtp', array ('host' => $host, 'auth' => true, 'username' => $username, 'password' => $password));

$mail = $smtp->send($to, $headers, $body);

if (PEAR::isError($mail)) { echo("<p>" . $mail->getMessage() . "</p>");

}

else

{

echo("<p>Message successfully sent!</p>");

}

;

} // function AfterAdd
M
monoofy author 3/3/2015

I hope I find a solution in this forum.
Thanks.

Sergey Kornilov admin 3/3/2015

This is a built-in feature, no need to use PEAR for this purpose.
http://xlinesoft.com/phprunner/docs/runner_mail_function.htm

See the latest example.

M
monoofy author 3/4/2015

Thanks Admin for your reply.

I've seen this page before, but I use pear mail to support authentication.

So, you may help me either to add authentication part for your example.

or to add attachment part for my code.

Really appreciated.

Sergey Kornilov admin 3/5/2015

PHPRunner's mail does support authentication, enter SMTP settings under Miscellaneous->Email settings.