PHP email failing to send with specific formatting character - php

I am trying to send an auto response email using PHP.
Here is the code for the body
$body = "<html><body>";
$body .= "Dear " . $_POST['contactName'].",";
$body .= "<br><br>";
$body .= "Welcome to......";
$body .= "<br><br>";
$body .= "Thank you for your application.";
$body .= "<br><br>";
$body .= "In order to further process your application could you please provide us <br>";
$body .= "with electronic copies of the following documents regarding your company:";
$body .= "<br><br>";
$body .= "- VAT Certificate";
$body .= "<br>";
$body .= "- Certificate of Incorporation";
$body .= "<br>";
$body .= "- Company Intro Letter";
$body .= "<br>";
$body .= "- Director's Passport";
$body .= "<br>";
$body .= "- Utility Bill of the Company and the Director";
$body .= "<br><br>";
$body .= "Please send electronic copies by email to: dinoangelides#gmail.com/";
$body .= "Once we have received these documents we will process your application.";
$body .= "<br><br>";
$body .= "If successful we will provide you with your secure login details,";
$body .= "<br>";
$body .= "which will allow you to access the website.";
$body .= "<br><br>";
$body .= "Please do not hesitate to contact us for any additional information required.";
$body .= "<br><br>";
$body .= "Best regards,";
$body .= "<br><br>";
$body .= '<img src="some link" width="202" height="59"/>';
$body .= "<br><br>";
$body .= "Support Team";
$body .= "<br>";
$body .= "IPVDX | B2B Experts";
$body .= "</body></html>";
now php send the email just fine but on this line
$body .= "Please send electronic copies by email to: dinoangelides#gmail.com/";
If i remove the / the email does not go....
and it does not let me put a break line below it to separate the two lines, therefore the message is connected at that point with the line below
any ideas why this is happening?

Related

Undefined variable: Body in PHP

I have been self-learning about our office websites over the past couple years and recently our original web person became unable to work on or help with the sites she had set up. Several of our websites have error logs that are filling up from undefined variable notifications. From my research, I believe I need to declare whatever it is giving the error. The example below is from one site with a reference to body. I am a php noob so I appreciate any help. If I add $body = Trim(stripslashes($_POST['body'])); below the human line, will that fix it? I'm afraid to get carried away with changes that might not be necessary since she can't repair any mistake I might make.
PHP Notice: Undefined variable: Body in email.php on line 48
<?php
$emailTo = "email#email.com"; // Email address you want submitted forms to go to
$Subject = "Email Inquiry"; // subject line for emails
$name = Trim(stripslashes($_POST['name']));
$phone = Trim(stripslashes($_POST['phone']));
$email = Trim(stripslashes($_POST['email']));
$mailheader = "From: $email \r\n";
$message = Trim(stripslashes($_POST['message']));
$human = Trim(stripslashes($_POST['human']));
// prepare email body text
$Body .= "Name: "; (this is line 48)
$Body .= $name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
This case.. Need to define the variable $Body before you doing String Concatenation.
// prepare email body text
$Body = ''; // define first
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";

Send url with variables through email body in 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 !

execute mail once all item have been iterated

I have the following issues.
I receive separate emails for each iteration of the loop. I want mail to be only sent once with all of the items iterated.
<?php
// Honey pot trap
// Create a hidden input that is only visible to bots. If it's empty than proceed.
if (empty($_POST['humancheck'])){
// Proceeed if submit button have been pressed
$fullName = $_POST['fname'];
$email = $_POST['email'];
$stage = $_POST['stage'];
include("db.php");
$resources = "select * from resources where stage LIKE '%".$stage."%'";
$run_query = mysqli_query($con, $resources);
while($row = mysqli_fetch_array($run_query)) {
$data[] = array(
'format' => $row['format'],
'title' => $row['title'],
'costs' => $row['cost'],
'stage' => $row['stage'],
'topic' => $row['topic'],
'link' => $row['link']
);
}
foreach($data as $item) {
// Sanitize input data
$clean_fullName = htmlspecialchars($fullName);
$clean_email = htmlspecialchars($email);
// Mail Set up
$to = $clean_email;
$to_us = "info#email.com";
// Email subject
$subject = "Your custom resource pack has arrived!";
$subject_us = "New custom resource delivered to: $clean_email";
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Based on your responses, we have created a custom resource pack tailored to your needs. <br><br>";
$message .= "<b>{$item['title']}</b><br>";
$message .= "{$item['format']} <br>";
$message .= "{$item['costs']} <br>";
$message .= "{$item['link']} <br><br>";
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
$message_us = "The below message was sent to $clean_fullName <br>
<i> Hi $clean_fullName <br>";
$message_us .= "\r\n Based on your responses, we have created a custom resource pack tailored to your needs: \r\n";
$message_us .= "\r\n If you have any questions, do not hesitate to reach out to us. \r\n";
// Headers
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info#email.com>' . "\r\n";
}
mail($to,$subject,$message,$headers);
mail($to_us,$subject_us,$message_us,$headers);
}
?>
what happens is the while loops to the data that is stored in an array. That array is used in foreach. and outside of the loops, the mail is suppose to mail the result.
In theory this should of worked but its not working.
Try this. Edit last part of your code in this way. Take one time parameters of mail content outside the loop, and let loop make only the message content.
$clean_fullName = htmlspecialchars($fullName);
$clean_email = htmlspecialchars($email);
$to = $clean_email;
$to_us = "info#email.com";
$subject = "Your custom resource pack has arrived!";
$subject_us = "New custom resource delivered to: $clean_email";
$message = '<html><body>';
$message .= "<p>";
$message .= "Hi $clean_fullName, <br><br>";
$message .= " Based on your responses, we have created a custom resource pack tailored to your needs. <br><br>";
foreach($data as $item) {
$message .= "<b>{$item['title']}</b><br>";
$message .= "{$item['format']} <br>";
$message .= "{$item['costs']} <br>";
$message .= "{$item['link']} <br><br>";
}
$message .= " If you have any questions, do not hesitate to reach out to us. <br><br>";
$message .= "</p>";
$message .= '</body></html>';
$message_us = "The below message was sent to $clean_fullName <br><i> Hi $clean_fullName <br>";
$message_us .= "\r\n Based on your responses, we have created a custom resource pack tailored to your needs: \r\n";
$message_us .= "\r\n If you have any questions, do not hesitate to reach out to us. \r\n";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <info#email.com>' . "\r\n";
mail($to,$subject,$message,$headers);
mail($to_us,$subject_us,$message_us,$headers);

Converting PHP script for generating email to work with variable rows in form

I am using a PHP script to generate an email based on the information from a form. The form has a variable number of rows.
I have converted the names of the inputs in each row in the form to an array, by adding [] after the name, so that the data in all of the rows is available for generating the email.
However, what I don't know how to do is how to construct the PHP so that it can generate an email with just the right number of rows in the email.
At the moment I have just set the PHP to read the first 5 items in the array for each input, and construct the body of the email using these. The problem with this approach is that if the user adds more than 5 rows data will be lost, and if there is less than 5 rows, there will be unnecessary text in the email for 'name, email, telephone'.
I wonder if there is a way of getting the PHP to read the array for any number of rows, and generate an email with just the correct number of rows? I have included the PHP as it stands below.
Thanks,
Nick
<?php
$EmailFrom = "";
$EmailTo = "";
$Subject = "";
$Name = Trim(stripslashes($_POST['name'][0]));
$Email = Trim(stripslashes($_POST['email'][0]));
$Telephone = Trim(stripslashes($_POST['telephone'][0]));
$Name2 = Trim(stripslashes($_POST['name'][1]));
$Email2 = Trim(stripslashes($_POST['email'][1]));
$Telephone2 = Trim(stripslashes($_POST['telephone'][1]));
$Name3 = Trim(stripslashes($_POST['name'][1]));
$Email3 = Trim(stripslashes($_POST['email'][1]));
$Telephone3 = Trim(stripslashes($_POST['telephone'][2]));
$Name4 = Trim(stripslashes($_POST['name'][1]));
$Email4 = Trim(stripslashes($_POST['email'][1]));
$Telephone4 = Trim(stripslashes($_POST['telephone'][3]));
$Name5 = Trim(stripslashes($_POST['name'][1]));
$Email5 = Trim(stripslashes($_POST['email'][1]));
$Telephone5 = Trim(stripslashes($_POST['telephone'][4]));
// validation
$validationOK=true;
if (!$validationOK) {
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
exit;
}
// prepare email body text
$Body = "New bookings have been made for the Ajahn Amaro Retreat as follows:";
$Body .= "\n";
$Body .= "\n";
$Body .= "name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "\n";
$Body .= "email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "\n";
$Body .= "telephone: ";
$Body .= $Telephone;
$Body .= "\n";
$Body .= "\n";
$Body .= "\n";
$Body .= "name: ";
$Body .= $Name2;
$Body .= "\n";
$Body .= "\n";
$Body .= "email: ";
$Body .= $Email2;
$Body .= "\n";
$Body .= "\n";
$Body .= "telephone: ";
$Body .= $Telephone2;
$Body .= "\n";
$Body .= "\n";
$Body .= "\n";
$Body .= "name: ";
$Body .= $Name3;
$Body .= "\n";
$Body .= "\n";
$Body .= "email: ";
$Body .= $Email3;
$Body .= "\n";
$Body .= "\n";
$Body .= "telephone: ";
$Body .= $Telephone3;
$Body .= "\n";
$Body .= "\n";
$Body .= "\n";
$Body .= "name: ";
$Body .= $Name4;
$Body .= "\n";
$Body .= "\n";
$Body .= "email: ";
$Body .= $Email4;
$Body .= "\n";
$Body .= "\n";
$Body .= "telephone: ";
$Body .= $Telephone4;
$Body .= "\n";
$Body .= "\n";
$Body .= "\n";
$Body .= "name: ";
$Body .= $Name5;
$Body .= "\n";
$Body .= "\n";
$Body .= "email: ";
$Body .= $Email5;
$Body .= "\n";
$Body .= "\n";
$Body .= "telephone: ";
$Body .= $Telephone5;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=payment.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>
Do something like this, iterating over one of the arrays of data:
foreach($_POST['name'] as $i => $name){
echo $name;
echo $_POST['email'][$i];
echo $_POST['telephone'][$i];
}
Except instead of printing the data, add it to the string that will be your email's body.
Instead of assigning each one to a unique variable, just put them in an array.
$body = '';
$row_count = count($_POST['name']);
for($i = 0; $i < $row_count; $i++)
{
// variable sanitation...
$name = trim(stripslashes($_POST['name'][$i]));
$email = trim(stripslashes($_POST['email'][$i]));
$telephone = trim(stripslashes($_POST['telephone'][$i]));
// this assumes name, email, and telephone are required & present in each element
// otherwise you will have spurious line breaks.
$body .= $name . "\n\n" . $email . "\n\n" . $telephone . "\n\n";
}
// send email
$success = mail($emailTo, $subject, $body, "From: <$EmailFrom>");
Also on a purely stylistic note, your variables should begin with lower-case letters.

Placing Form Result on confirmation page not working!

I can't figure out why the first name is not picking up on the confirmation page?
<div class="tu">Thank you, <?php echo $_GET['sender_first_name']; ?>.</div>
<?php
$sender_first_name = $_REQUEST['sender_first_name'] ;
$sender_last_name = $_REQUEST['sender_last_name'] ;
$sender_email = $_REQUEST['sender_email'] ;
$sender_message = $_REQUEST['sender_message'] ;
$friend_first_name = $_REQUEST['friend_first_name'] ;
$friend_last_name = $_REQUEST['friend_last_name'] ;
$friend_email = $_REQUEST['friend_email'] ;
$Body = "";
$Body .= "Sender's First Name: ";
$Body .= $sender_first_name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Sender's Last Name: ";
$Body .= $sender_last_name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Sender's Email: ";
$Body .= $sender_email;
$Body .= "\n";
$Body .= "\n";
$Body .= "Sender's Message: ";
$Body .= $sender_message;
$Body .= "\n";
$Body .= "\n";
$Body .= "------------------------------------------------------------------ \n";
$Body .= "\n";
$Body .= "Friend's First Name: ";
$Body .= $friend_first_name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Friend's Last Name: ";
$Body .= $friend_last_name;
$Body .= "\n";
$Body .= "\n";
$Body .= "Friend's Email: ";
$Body .= $friend_email;
$Body .= "\n";
$Body .= "\n";
$Body .= "Sent Date: ";
$Body .= date("Y-m-d H:i A e");
mail( "eriksnet#mac.com", "Message From Myorphan.com - Tell A Friend Request",
$Body, "From: $email" );
header("Location: http://www.feedmyorphan.com/friend_confirm.php?name=" . urlencode($sender_first_name));
?>
Are you sure the form was submitted by way of GET and not POST? if you used POST then you're looking for $_POST['sender_first_name'];
It looks pretty obvious to me!
<div class="tu">Thank you, <?php echo $_GET['sender_first_name']; ?>.</div>
Are you sure it is a $_GET[' ']?
I'd go for:
<div class="tu">Thank you, <?php echo $_REQUEST['sender_first_name']; ?>.</div>
Because the data was sent from a form, wasn't it?
And also, $Body = ""; does not need to be written. (among other stuff)

Categories