I am the outsider for using script.
I am trying use AddEmbeddedImage and cid: to embed image from attachment, is that correct?? But failure...
Thank you very much for your help in advance !!!
$signature = $_POST['signature'];
$signatureFileName = uniqid().'.png';
$signature = str_replace('data:image/png;base64,', '', $signature);
$signature = str_replace(' ', '+', $signature);
$data = base64_decode($signature);
$file = 'signatures/'.$signatureFileName;
file_put_contents($file, $data);
$message='Subject: '.$_POST['subject'].'<br />
<img src="cid:'.uniqid().'.png"/> <br />
<img src="cid:'.uniqid().'"/> <br />
';
require "../phpmailer/class.phpmailer.php";
require "../phpmailer/setting.php";
$mail->Subject = "Image Form";
$mail->MsgHTML($message);
$mail->AddEmbeddedImage($file, uniqid());
You are calling uniqid() multiple times, and as the docs say, each time it will give you a new, random result, so your attachment CIDs will never match what's in your message content. Do it like this to ensure they match:
$cid = uniqid();
$message='Subject: ' . $_POST['subject'] . '<br />
<img src="cid:' . $cid . '"/> <br />';
$mail->addEmbeddedAttachment($file, $cid);
Related
I am trying to send several images in the body of the email. When I send one it works. But as soon as I want to send several it does not work anymore.
I tried doing a for loop but without result. I have also tried adding addEmbeddedImage several times with a different cid for each image.
if(array_key_exists('submit', $_POST)){
if (array_key_exists('userfile', $_FILES)) {
$uploadfile = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile']['name']));
$uploadfile2 = tempnam(sys_get_temp_dir(), hash('sha256', $_FILES['userfile2']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile) ) {
require './vendor/autoload.php';
$prenom = $_POST['prenom'];
$nom = $_POST['nom'];
$q1 = $_POST['q1'];
$q1_2 = $_POST['q1_2'];
$q2 = $_POST['q2'];
$q2_2 = $_POST['q2_2'];
$mail = new PHPMailer;
$mail->isHTML(true);
// $mail->isSMTP();
// $mail->SMTPDebug = 2;
$mail->Host = 'ssl0.ovh.net';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->CharSet = 'UTF-8';
$mail->setFrom('lol#example.com', $prenom);
$mail->addAddress('info#nicolaspoulain.be', 'Jessica');
$mail->Subject = 'Formulaire de sécurité VCA';
$mail->AddEmbeddedImage($uploadfile, "my-attach");
$mail->AddEmbeddedImage($uploadfile2, "my-attach2");
$mail->Body =
'<h1 style= "text-align: center;" margin-bottom:"100px;"> Formulaire de visite sécurité</h1>
<h4>Prénom: </h4>' . strip_tags($prenom) .
'<h4>Nom: </h4>' . strip_tags($nom) .
'<table rules="all" style="border-color: #666;" cellpadding="10">
<tr><th style="width: 40%;">Question</th><th style="width: 10%;">Réponse</th><th style="width: 50%;">Commentaires</th></tr>
<tr style="background: #eee;"><td><strong>Y a-t-il un permis de travail?</strong> </td><td>' . strip_tags($q1) . "</td><td>" . strip_tags($q1_2) . '<img src="cid:my-attach">' . "</td></tr>
<tr style='background: white;'><td><strong>La description de la tâche et les mesures de sécurité sont-elles suffisamment claires?</strong> </td><td>" . strip_tags($q2) . "</td><td>" . strip_tags($q2_2) . '<img src="cid:my-attach2">' . "</td></tr>";
if (!$mail->send()) {
$msg .= "Mailer Error: " . $mail->ErrorInfo;
} else {
$msg .= "L'audit a bien été transmis!";
}
} else {
$msg .= 'Failed to move file to ' . $uploadfile;
}
}
}
Good afternoon,
To be able to add multiple images in the body of the email. You should use CID's.
$imgPath = "\images\Progressiva_Itaipu.jpg";
$cid = md5($imgPath);
$mail->AddEmbeddedImage($imgPath,$cid,'Progressiva_Itaipu.jpg');
Calling so in the body of the message
$message .= "<img src='cid:$cid'>";
If it is multiple images, you can do the foreach or even a for
The following function works but I am unable to control the font-size of the "Subject". Is there a way to change the font size of the "Subject". I've tried:
$mail->Subject = "<span style='font-size:3vw'>" .$mailInputs['subject'] ."<\span>";
but that didn't work.
function mailerExpressBlueHost(array $mailInputs){
require_once '../includes/phpmailer/PHPMailerAutoload.php';
$mail = new PHPMailer();
$mail->IsMail();
$mail->SetFrom('example#xyz.com');
$mail->IsHTML(true);
$mail->addAddress('abc#example.com');
$mail->AddEmbeddedImage("../public/img/swb.jpg", "swb-image");
$body = '<!DOCTYPE html>
<html><header>
</header>
<body lang=EN-US>
<div style="text-align:center">
<img src="cid:swb-image">' . $mailInputs['body'] ;
$mail->isHTML(true);
$mail->Subject = $mailInputs['subject'] ;
$mail->Body = $body;
if(!$mail->send()) {
return 'Message could not be sent.' . 'Mailer Error: ' . $mail->ErrorInfo;
} else {
return 'Message has been sent';
}
$mail->ClearAddresses();
}
No, you can't do this. The Subject line does not support HTML formatting; it's plain text only - not least because the definition of the Subject email header predates HTML by at least 10 years.
On the upside, you can use unicode, which allows you quite a lot of tricks, but it's highly dependent on the OS and application it's viewed in.
I am running phpmailer and very much new to it.
Problem definition: Not able to see php variables data in the received email while html content can seen properly.
Below is some of the code:
require 'PHPMailer/class.phpmailer.php';
$mail = new PHPMailer;
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->IsHTML(true); // Set email format to HTML
$mail->Subject = 'Message';
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong> <?php echo "$name";?> <?php echo "$place";?>
</body>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->Send()) {
echo 'Message could not be sent.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
echo 'Message has been sent';
Not able to see data defined under php.
Also $name and $place is the dynamic data for the every mail.
Please help.
You cannot put php statements in single quotes. use the following instead:
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>' . $name . ' ' . $place . '
</body>';
You need to put the text between " instead of '.
PHP only replaces variables in double quoted strings.
Also you shouldn't use php code in the strings.
$mail->Body = "
<body>
<div align=\"center\"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong> $name $place
</body>
";
try instead :
$mail->Body = "<body>
<div align=\"center\"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>$name $place
</body>";
You don't have to put php tags in your string since you are already in a php context !
Replace Body with :
$mail->Body = '<body>
<div align="center"><p7><strong>HELLO WORLD</strong></p7></div>
<h9><u>Details</u></h9><br/>
<h9><strong>NAME:</strong>'.$name.' '.$place.'</body>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message .= "Phone: 0181-4606260.<br>";
$message .="Mobile :09417608422.<br>";
Send_Mail('abc#example.com','Welcome',$message,$headers);
try this...
I create a popup window using onclick="window.open()" the question is how can i get the data from previous page? here is my code :
<?php
include ("conn.php");
extract($_GET);
$applicantID = $_GET['applicantID'];
$sql = "SELECT * FROM applicant WHERE applicantID ='$applicantID'";
$query = mysql_query($sql);
$data = mysql_fetch_array($query);
echo $data['applicantID'];
?>
When i echo $data['applicantID']; it doesn't show any data.
I use this <input type="button" value="Check" onclick="window.open('checkstatus.php','popup','width=800,height=800,scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no,left=0,top=0'); return false" />
Why don't you use window.open('checkstatus.php?applicantID=something')? And retrieve it by $applicantID = $_GET['applicantID'] so that I hope it will work.
suppose that a simple html dom object includes the following
text1
<br />
<br />
<br />
text2
<br />
How can i get either of texts using simple html dom?
Just use plaintext to get text value from html.
$opts = array(
'http' => array(
'method' => "GET",
'header' => "Accept-language: en\r\n" .
"User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US;
rv:1.9.1.6) Gecko/20091201 Firefox/3.5.6\r\n" .
"Cookie: foo=bar\r\n"
)
);
$context = stream_context_create($opts);
$html1 = new simple_html_dom();
$html1->load_file($url, false, $context);
$appName1 = $html1->find('tagname.classname or id', 0)->plaintext;
For class use (tagname.classname) and for id use (tagname#id) to get text.
$context is for set header for browser support if any website get mobile version so u can add header to get browser support content.
To grab all plain text elements, you can use the following:
$string="text1
<br />
<br />
<br />
text2
<br />";
$html = str_get_html($string);
$texts=$html->find('text');
foreach($texts as $elem_index => $text){
echo $elem_index."=>".$text."<br>";
}
Your output should look something like this:
0=>text1
1=>
2=>
3=> text2
In the foreach loop, you can obviously do whatever filtering you need to. For instance, if you're trying to find some text that matches a specific string, you can simply do:
if (trim($text) == "text2")
//do something
So, if you wanted to replace the found text, you could use:
if (trim($text) == "text2")
$texts[$elem_index]->innertext = "something else";
$html->save();
and $html will contain the new html.
With jquery try $(document.body).contents();
This should you a array of node with the text1 and text2 as text node.