-
Notifications
You must be signed in to change notification settings - Fork 0
/
send_email.php
47 lines (40 loc) · 1.63 KB
/
send_email.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
// require "./worker/db_worker.php";
// require_once ('/app/vendor/autoload.php');
require 'vendor/autoload.php';
class SendEmail{
// use SendGrid\Mail\Mail;
public static function SendMail($to,$subject,$content, $attachment_content){
$key = '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';
$email = new \SendGrid\Mail\Mail();
$email->setFrom("[email protected]","rtcamp");
$email->setSubject($subject);
$email->addTo($to);
$email->addContent("text/html",$content);
$sendgrid = new \SendGrid($key);
// Attachment code
$content = file_get_contents($attachment_content[0]);
$attachment = new \SendGrid\Mail\Attachment();
$attachment->setType("multipart/mixed");
$attachment->setFilename($attachment_content[1].".png");
$attachment->setContentId($attachment_content[1]);
$attachment->setDisposition("attachment");
$attachment->setContent($content);
$email->addAttachment($attachment);
try{
$response = $sendgrid->send($email);
echo "Mail sent successfully";
}catch(Exception $e){
echo 'Email exception Caught : '. $e->getMessage() ."\n";
return false;
}
// $sendgrid = new SendGrid($key);
// $email = new \SendGrid\Mail\Mail();
// $email->addTo($to)
// ->setFrom("[email protected]")
// ->setSubject("Sending with SendGrid is Fun")
// ->setHtml("and easy to do anywhere, even with PHP");
// $sendgrid->send($email);
}
}
?>