-
Notifications
You must be signed in to change notification settings - Fork 0
/
createEmail.php
executable file
·45 lines (36 loc) · 1.36 KB
/
createEmail.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
#!/usr/bin/php
<?php
require_once 'swift/lib/swift_required.php';
require_once 'config.php';
if ($argc < 2)
die("Provide filename\n");
$mailFilePath = $argv[1];
if (!file_exists($mailFilePath))
die ("File doesn't exists\n");
$body = fread(fopen($mailFilePath, 'r'), filesize($mailFilePath));
$transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'sslv3')
->setUsername($mailer_config['gmail_username'])
->setPassword($mailer_config['gmail_password']);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance(basename($mailFilePath))
->setFrom($mailer_config['sender'])
->setTo($mailer_config['recipients']);
preg_match_all('/(background="([^<>\"]*)|src="([^<>\"]*)|url\(([^\(\)]*)\))/', $body, $matches);
if (count($matches) > 2){
$images = array();
for ($i = 2; $i < count($matches); $i++){
foreach ($matches[$i] as $key => $value)
if (!empty($value)){
$path = dirname($mailFilePath).'/'.$value;
$handle = fopen($path, "r");
$data = fread($handle, filesize($path));
$src = $message->embed(Swift_Image::newInstance($data, basename($path), 'image/png'));
$body = str_replace($value, $src, $body);
$images[$value] = $src;
}
}
}
print_r($images);
$message->setBody($body, 'text/html');
print "success sents - ".$mailer->send($message);
print "\n";