-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsendEmail.php
61 lines (50 loc) · 2.21 KB
/
sendEmail.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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
<?php
date_default_timezone_set( "Asia/Taipei" );
include_once "C:/xampp/htdocs/www/adoConnection.php";
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
// load Composer's autoloader
require 'C:/xampp/htdocs/www/vendor/autoload.php';
$mail = new PHPMailer( true );
try {
// setup phpmailer
$mail->isSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = "YOUR_EMAIL";
$mail->Password = "YOUR_EMAIL'S_PASSWORD";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->charSet = "UTF-8";
$sql = "select item.id as id , item.item_subject as subject , item.item_remark as remark ,
user.email as email , user.name as username
from remind_item as item , remind_user as user
where '" . date( "Y-m-d H:i:s" ) . "' = notify_datetime
and item.user_guid = user.id and item.is_delete = 0 and item.notify = 1";
// reminder id , subject , remark , email , user name
$result = $conn->execute( $sql );
if ( $result->EOF ) {
echo date( "Y-m-d H:i" ) . "--no email send\n";
}
while ( !$result->EOF ) {
// set sender
$mail->setFrom( "YOUR_EMAIL" , "reminder" );
// set receiver
$mail->addAddress( $result->fields[ "email" ] , $result->fields[ "username" ] );
$mail->Subject = mb_encode_mimeheader( $result->fields[ "subject" ] , "UTF-8" );
$remark = ( $result->fields[ "remark" ] == "" ? "無" : $result->fields[ "remark" ] );
$username = $result->fields[ "username" ];
$subject = $result->fields[ "subject" ];
$body = "收件者: " . $username . "\n" . "主題: " . $subject . "\n" . "備註: " . $remark . "\n";
$mail->Body = $body;
$mail->send();
$id = $result->fields[ "id" ];
echo date( "Y-m-d H:i" ) . "--mail send ( reminder item id = $id )\n";
$result->moveNext();
}
}
catch ( Exception $e ) {
echo "mail could not be send( reminder id = $id ) " . $mail->ErrorInfo;
}
$conn->close();
?>