Send url with variables through email body in Php - php

Trying to build a code to send password reset link through email in response to those who request it.
The email is received on hotmail and gmail, but not on particular mail client I do not know the configuration.
Of course, I tried several arrangements regarding the quotes and doubles-quotes, but it did not give anything.
<?php
$site = "http://www.example.fr";
$from = "info#example.fr";
$nom = "DLSS";
$limite = "_----------=_parties_".md5(uniqid (rand()));
$sujet = "Password Reset";
$text = "Please click on this link to initialize your password.";
$html = "Please click on this link to initialize your password.";
$from = $nom." <".$from.">";
$header = "From: ".$from."\n";
$header .= "Reply-to: ".$from."\n";
$header .= "Return-Path: ".$from."\n";
$header .= "Organization: ".$nom."\n";
$header .= "X-Sender: <".$site.">\n";
$header .= "X-Mailer: PHP/".phpversion()."\n";
$header .= "X-auth-smtp-user: ".$from." \n";
$header .= "X-abuse-contact: ".$from." \n";
$header .= "Date: ".date("D, j M Y G:i:s O")."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";
$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain\n";
$message .= "charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $text;
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $html;
$message .= "\n--".$limite."--";
mail($eml, $sujet, $message, $header);
?>
In summary, the email is received by this particular mail client when I replace these two lines there :
$text = "Please click on this link to initialize your password.";
$html = "Please click on this link to initialize your password.";
With these two lines here :
$text = "Test Email with link. link";
$html = "Test Email with link. link";
Or with these two lines here :
$text = $eml . " - " . $cod;
$html = $eml . " - " . $cod;
Finally, the problem is in the combination of these two parts that are the web address and the two variables, it's been three days that I try to solve this problem but I can not do it alone, it would be really nice to have help, Thanks in advance !

Related

outlook doesn't recognise base64 encoded attachment (gmail does)

I'm learning how to attach a base64 encoded image to an email generated in php and sent using AWS. Sending to my gmail address it seems to work perfectly but sending to an account picking up with outlook 2003, there is an attachment but it's 142B.
It seems to me that this is either an outlook settings problem or that gmail is forgiving an error of mine that outlook doesn't.
$pName = "frank";
$pSubject = "test email";
$pToEmail ="me#gmail.com"; // alternate = "me#work.com" picked up on outlook 2003
$attachedFile = '/Code/test.jpg';
$check = getimagesize($attachedFile);
$message = "To: $pName <". $pToEmail .">\n";
$message .= "From: Frank <franki#franki.co.uk>\n";
$message .= "Subject: ".$pSubject."\n";
$message .= "MIME-Version: 1.0\n";
$message .= 'Content-Type: multipart/mixed; boundary="frankis_image_boundary_02122016"';
$message .= "\n\n";
$message .= "--frankis_image_boundary_02122016\n";
$message .= 'Content-Type: text/plain; charset="utf-8"';
$message .= "\n";
$message .= "Content-Transfer-Encoding: 7bit\n";
$message .= 'Content-Disposition: inline';
$message .= "\n\n";
$message .= "Dear new tester,\n\n";
$message .= "Attached is the file you requested.\n";
$message .= "\n\n";
$message .= "--frankis_image_boundary_02122016\n";
$message .= "Content-ID: <test.jpg#domain.com>\n";
$message .= 'Content-Type: '.$check['mime'].'; name="test.jpg"';
$message .= "\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= 'Content-Disposition: attachment; filename="test.jpg"';
$message .= "\n";
$message .= base64_encode(file_get_contents($attachedFile));
$message .= "\n";
$message .= "--frankis_image_boundary_02122016--\n";
$sendMsg['RawMessage']['Data'] = (string)base64_encode($message);
$sendMsg['RawMessage']['Source'] = "franki#franki.co.uk";
$sendMsg['RawMessage']['Destinations'] = array($pToEmail);
//$client appropriately set up here
$result = $client->sendRawEmail($sendMsg);
Many searches here discuss problems embedding images in outlook, I just want it to send as an attachment. Any solutions or suggestions appreciated.

Send email with the pdf attachment in php

I m new to php. I need to send the email with the pdf attachment.I m able to send an email with the attachment. But unable to open the pdf. I get the some error like this
"Acrobat could not oen 'file_name' because it is either not a supported file type or because the file has been damaged(for example, it was sent as an email attachment and wasn't correctly decoded)..."
If someone could help me resolve this problem, that would be great. Thanks!
Here is my code:
$to = 'form#kronova.in, ' . $Email;
$subject = 'ABC :: Admission Form Details';
$repEmail = 'form#kronova.in';
$fileName = 'ABC-Admission.pdf';
$fileatt = $pdf->Output($fileName, 'E');
$attachment = chunk_split($fileatt);
$eol = PHP_EOL;
$separator = md5(time());
$headers = 'From: Principal abc <'.$repEmail.'>'.$eol;
$headers .= 'MIME-Version: 1.0' .$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$message = "--".$separator.$eol;
$message .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
$message .= "Thanks for filling online application form. Your online admission registration number is E0000". mysql_insert_id() . "." .$eol;
$message .= "--".$separator.$eol;
$message .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$message .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$message .= "--".$separator.$eol;
$message .= "Content-Type: application/pdf; name=\"".$fileName."\"".$eol;
$message .= "Content-Transfer-Encoding: base64".$eol;
$message .= "Content-Disposition: attachment".$eol.$eol;
$message .= $attachment.$eol;
$message .= "--".$separator."--";
if (mail($to, $subject, $message, $headers)){
echo "Email sent";
}
else {
echo "Email failed";
}
Try this:
$attachment = chunk_split(base64_encode($fileatt));
Instead of
$attachment = chunk_split($fileatt);

Emailing user works but not admin?

I have an order form that is processed and the customer receives the email, however, adding in the admin bit doesn't email the admin?
The following code is the bit that sends to the customer (which works fine) and also the code that should also email the admin but doesn't :(
// email stuff (change data below)
$to = $payment_data['sold_to_email'];
$from = $order_options['admin_email'];
$subject = "Your Order";
//include the message
$message = $order_options['email_message'];
//Build the Order out
$message .= '<br /><br />Thank you for purchasing from us';
// a random hash will be necessary to send mixed content
$separator = md5(time());
// carriage return type (we use a PHP end of line constant)
$eol = PHP_EOL;
// main header (multipart mandatory)
$headers = "From: ". $company . " <" . $from . ">". $eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"".$eol.$eol;
$headers .= "Content-Transfer-Encoding: 7bit".$eol;
$headers .= "This is a MIME encoded message.".$eol.$eol;
// message
$headers .= "--".$separator.$eol;
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$headers .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
//$headers .= $message.$eol.$eol;
// send message
$sendit = wp_mail($to, $subject, $message, $headers);
$admin_message = $payment_data['admin_field'];
wp_mail($admin_email, 'New Order', $admin_message);
//Code to troubleshoot email problems.
/* if(!$sendit) {
$tempOptions = get_option('order_options');
$tempOptions['admin_email'] = "EMAIL FAILED";
update_option('order_options', $tempOptions);
}
*/

Why isn't my gmail or yahoo email accounts receiving mail when I use this PHP mail function

The send_mail function with the headers. What could be blocking this from being received. I know it works at least sometimes, my work email receives it just fine.
Another thing that might be of note:
- with a different ssl page the function did send correctly to gmail
- on this totally separate domain, it is not.
function send_mail($from,$fromName,$to,$object,$bodyText,$bodyHtml){
$site = "mywebsite.ca";
$from = $fromName." <".$from.">";
$limite = "_----------=_parties_".md5(uniqid (rand()));
$header = "Reply-to: ".$from."\n";
$header .= "From: ".$from."\n";
$header .= "X-Sender: <".$site.">\n";
$header .= "X-Mailer: PHP\n";
$header .= "X-auth-smtp-user: ".$from." \n";
$header .= "X-abuse-contact: ".$from." \n";
$header .= "Date: ".date("D, j M Y G:i:s O")."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";
$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain\n";
$message .= "charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $bodyText;
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $bodyHtml;
$message .= "\n--".$limite."--";
if(mail($to, $object, $message, $header)) return true;
else return false;
}
if(mail($to, $object, $message, $header)) return true;
else return false;
heres the code that send the mail to your email try to debug it it all the variable inside specially the $to varible because its your email where the message will be send.
try this
if(mail($to,$object,$message,$header)){
//echo all
}
else{
//echo mssage not submit
}
Why are you merging Text and HTML content type in same variable ?
$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain\n";
$message .= "charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $bodyText;
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $bodyHtml;
Use any one of them only
like instead of above
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $bodyHtml;

PHP Email Formatting Issue

I am sending form data through a .swf file into this PHP page.(see below) When the email is sent, if there is an attachment the body of the message will not appear but if there is not an attachment the body appears just fine. I know that all of the variable names are correct because all of the data has been passed from the swf file. Is there something in the way I have set up the email that makes it work that way? Please let me know.
<?php
$to=$_POST['toEmail'];
$subject=$_POST['subject'];
$body = $_POST['messaggio'];
$nome = $_POST['nome'];
$email = $_POST['email'];
$attach = $_POST['attach'];
$headers = "From: $nome<" . $email . ">\n";
if ($attach == 1) {
$tmp_name = $_FILES['Filedata']['tmp_name'];
$type = $_FILES['Filedata']['type'];
$name = $_FILES['Filedata']['name'];
if(is_uploaded_file($tmp_name)){
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
$headers .= "Reply-To: <" . $email . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: multipart/related; type=\"multipart/alternative\"; boundary=\"----=MIME_BOUNDARY_main_message\"\n";
$headers .= "X-Sender: $to <" . $to . ">\n";
$headers .= "Return-Path: <" . $email . ">\n";
$headers .= "This is a multi-part message in MIME format.\n";
$headers .= "------=MIME_BOUNDARY_main_message \n";
$headers .= "Content-Type: multipart/alternative; boundary=\"----=MIME_BOUNDARY_message_parts\"\n";
$message = "------=MIME_BOUNDARY_message_parts\n";
$message .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: quoted-printable\n";
$message .= "\n";
$message .= $body . "\n";
$message .= "\n";
$message .= "------=MIME_BOUNDARY_message_parts--\n";
$message .= "\n";
$message .= "------=MIME_BOUNDARY_main_message\n";
$message .= "Content-Type: application/octet-stream;\n\tname=\"" . $name . "\"\n";
$message .= "Content-Transfer-Encoding: base64\n";
$message .= "Content-Disposition: attachment;\n\tfilename=\"" . $name . "\"\n\n";
$message .= $data;
$message .= "\n";
$message .= "------=MIME_BOUNDARY_main_message--\n";
mail($to, $subject, $message, $headers);
}
} else {
if(mail($to, $subject, $body, $headers)) {
echo "ok=1";
}
}
?>
Building MIME messages, especially with attachments, is painful. You'd be better off using something like PHPMailer, which will handle the whole business for you automatically... You just have to provide the content.
Beyond that, you're slurping the attachments into memory. How big are they? Are you exceeding the script's memory_limit?

Categories