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)
Related
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";
When I send mail from php and the type message in ckeditor textarea, I get mail like below:
I want to remove \n\n
Thanks in advance.
Here my code
<?php
$to = $resrow['recevie_email'];
$subject = $esub;
$message = "Hi Admin,<br>";
$message .= "<br/><br/>";
$message .= "There is a query from user described below.<br>";
$message .= "Name : ".$_SESSION['first_name'] ." ".$_SESSION['last_name'];
$message .= "<br/>";
$message .= "ROLE : ".$mail_from;
$message .= "<br/>";
$message .= "Email : ".$_SESSION['EMAIL'];
$message .= "<br/>";
$message .= "Phone : ".$userdetail['phone'];
$message .= "<br/>";
$message .= "Query : ".$data;
$message .= "<br><br>";
$message .= "Please contact ".$mail_from." on above details to resolve the query.";
$message .= "<br><br>";
$message .= "Thank you,<br>";
$message .= "Elevon Team.";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: Elevon <'.$resrow['send_email'].'>';
$message = trim($message, "\n");
$mail_conf = mail($to, $subject, $message, implode("\r\n", $headers));
?>
Ok, here i found the answer, to remove \n\n from mail message body we have to just use str_replace as below
$data = str_replace('\n',' ',$data);
Here the full code
<?php
$data = str_replace('\n',' ',$data);
$to = $resrow['recevie_email'];
$subject = $esub;
$message = "Hi Admin,<br>";
$message .= "<br/><br/>";
$message .= "There is a query from user described below.<br>";
$message .= "Name : ".$_SESSION['first_name'] ." ".$_SESSION['last_name'];
$message .= "<br/>";
$message .= "ROLE : ".$mail_from;
$message .= "<br/>";
$message .= "Email : ".$_SESSION['EMAIL'];
$message .= "<br/>";
$message .= "Phone : ".$userdetail['phone'];
$message .= "<br/>";
$message .= "Query : ".$data;
$message .= "<br><br>";
$message .= "Please contact ".$mail_from." on above details to resolve the query.";
$message .= "<br><br>";
$message .= "Thank you,<br>";
$message .= "Elevon Team.";
$headers[] = 'MIME-Version: 1.0';
$headers[] = 'Content-type: text/html; charset=iso-8859-1';
$headers[] = 'From: Elevon <'.$resrow['send_email'].'>';
$message = trim($message, "\n");
$mail_conf = mail($to, $subject, $message, implode("\r\n", $headers));
?>
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?
I have this piece of PHP code, although it works, but the problem is that the email message content is sent as an attachment along with the intended attachment which means that when the email arrives, the body is blank but there's two attachments. One is the intended attachment and the other is the email content that is supposed to be displayed in the the email. Is there something I'm doing wrong?
Here's the full source code:
<?php
require('fpdf/fpdf.php');
include('./config.php');
$pdf = new FPDF('P', 'pt', 'Letter');
$pdf->SetAutoPageBreak(true, $margin);
$pdf->AddPage();
$pdf->SetFont('arial','',12);
if(isset($_POST['accept'])){
$id = $_POST['id'];
$to = 'me#somewhere.com';
$subject = urldecode($_POST['subject']);
$message = urldecode($_POST['message']);
$data = '';
$result = mysql_query("select * from applications where id = $id");
$row = $data_array = mysql_fetch_assoc($result);
$data .= "Name: " . $row['name'] . " \n\n";
$data .= "Surname: " . $row['surname'] . "\n\n";
$data .= "Age: ". $row['age'] . "\n\n";
$data .= "Dob: ". $row['dob'] . "\n\n";
$data .= "Height: ". $row['height'] . "\n\n";
$data .= "Add1 : ".$row['address1'] . "\n\n";
$data .= "Add2: ".$row['address2'] . "\n\n";
$data .= "Add3: ".$row['address3'] . "\n\n";
$data .= "Postcode: ".$row['postcode'] . "\n\n";
$data .= "Town: ".$row['town'] . "\n\n";
$data .= "County: ". $row['county']. "\n\n";
$pdf->SetX(140);
$pdf->Ln(2);
$pdf->MultiCell(0, 15, $data);
$from = "me#mydomain.com";
$separator = md5(time());
$eol = PHP_EOL;
// attachment name
$filename = "form.pdf";
// encode data (puts attachment in proper format)
$pdfdoc = $pdf->Output("", "S");
$attachment = chunk_split(base64_encode($pdfdoc));
// main header
$headers = "From: ".$from.$eol;
$headers .= "MIME-Version: 1.0".$eol;
$headers .= "Content-Type: multipart/mixed; boundary=\"".$separator."\"";
$body = "--".$separator.$eol;
$body .= "Content-Transfer-Encoding: 7bit".$eol.$eol;
// message
$body .= "--".$separator.$eol;
$body .= "Content-Type: text/html; charset=\"iso-8859-1\"".$eol;
$body .= "Content-Transfer-Encoding: 8bit".$eol.$eol;
$body .= $message.$eol;
// attachment
$body .= "--".$separator.$eol;
$body .= "Content-Type: application/octet-stream; name=\"".$filename."\"".$eol;
$body .= "Content-Transfer-Encoding: base64".$eol;
$body .= "Content-Disposition: attachment".$eol.$eol;
$body .= $attachment.$eol;
$body .= "--".$separator."--";
// send message
if(mail($to, $subject, $body, $headers)){
echo "<b>Email successfully sent</b>";
}
else{
echo "Your message could not be sent.";
}
}
?>
Any help will be highly appreciated.
I actually have some experience with single-handedly writing this kind of thing from scratch. After years of maintaining a home-brewed PHP e-mail builder, my advice is that you shouldn't. It certainly takes less time and resources to research and find the most well-supported, mainstream solution today (whenever today is) than to write your own (and to pay for all the inherent bugs with your time and/or resources).
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.