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";
Related
new to the forum and trying my hand at some coding to help out a friend who cant seem to get this right..
with that being said, i was originally having issues with the contact form on a website not being able to send an email. after a bit of searching on the net and adding a few components here and there it is finally working, but now i have an additional problem..
when the email gets sent through (this is a business website and it sends an email from there to the relevant sales department etc) its all shoved into one line and looks terrible..
like this-
"Name: TEST EMAIL FROM WEBSITETel: 011 937 0572Email:
myemail#zmail.comMessage: TEST PLEASE CONFIRM
test 38"
what i have not been able to find is how to seperate the text so that it comes through in an email as seperate lines like this-
Name: Client
Tel: 011 000 0000
Email: myemail#zmail.com
Message: text here etc.
i have linked the contact form to a .php document, so i would presume that it is in this document that the change would need to take place?? i have tried to add in <br /> & <div> but neither do anything except give me an error message when i try send form from the site.
here is the code for the contactgenie.php linked to the contact form that works 100%
<?php
$EmailFrom = "myeamail#zmail.co.za";
$EmailTo = "myemail#zmail.co.za";
$Subject = "Company Name - Online Enquiry";
$Name = Trim(stripslashes($_POST['Name']));
$Tel = Trim(stripslashes($_POST['Tel']));
$Email = Trim(stripslashes($_POST['Email']));
$Message = Trim(stripslashes($_POST['Message']));
// validation
$validationOK=true;
if (!$validationOK) {
print "There has been an error, please make sure you entered a correct email address."; // You can edit this to your own error message
exit;
}
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "";
$Body .= "Message: ";
$Body .= $Message;
$Body .= "";
// send email
$success = mail($EmailTo, $Subject, $Body, $Headers = "From: <$EmailFrom\r\n");
// redirect to success page
if ($success){
print "Thank you, your email has been sent! We will be in touch shortly!"; // You can edit this to your own success message
}
else{
print "There has been an error, please make sure you have entered your details correctly."; // You can edit this to your own error message
}
?>
any help with this would be greatly appreciated, thanks
Dillon
You could pre-format the mail body using standard line breaks within double quotes like this:
$Body = "
Name: {$Name}
Tel: {$Tel}
Email: {$Email}
Message: {$Message}";
To achive the double line-height you insert another return between the lines:
$Body = "
Name: {$Name}
Tel: {$Tel}
Email: {$Email}
Message: {$Message}";
thanks for all your help guys! i got it to work, i added "\n" into the code and it works perfectly, i just need it to seperate the text so that it is easier to read when the email comes through from the site, thanks again really helped me out with this!
add <br/> tag to add new line space with your variables like this
$Body = "";
$Body .= "Name: ";
$Body .= $Name.'<br/>';
and wherever else you want to add new line space
for this your must be in HTML form
because there are two type of email html and richtext. takecare of that also.
Not sure if this works but if it's HTML email, this should work.
$Body .= '<html><body>';
$Body .= "Name: ";
$Body .= $Name;
$Body .= "<br>";
$Body .= "Tel: ";
$Body .= $Tel;
$Body .= "<br>";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "<br>";
$Body .= "Message: ";
$Body .= wordwrap($Message, 50);
$Body .= '</body></html>';
The message may or may not work. Don't get your hopes up to high on that part.
add <br/> tag to add new line space with your variables like this
$Body = "Name : " $Name ."<br/>";
$Body .= "Tel : " $Tel ."<br/>";
$Body .= "Email : " $Email ."<br/>";
$Body .= "Message: " $Message ."<br/>";
Don't use break tag, it is not working.You can easily use "\r\n" as line break
$Body = "Name : ". $name ."\r\n"."Email : " . $email ."\r\n"."Contact : " . $contact;
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 a contact form on a html page. The form data is sent to a PHP page which sends the info to an email address. It works for addresses *#gmail, *#hotmail.com but the person who needs to receive it has Outlook set-up for their website.com address and it doesn't work. Is there another setting I need somewhere?
Here is PHP code:
<?php
$EmailFrom = "myname#website.com";
$EmailTo = "receiver#website.com";
$Subject = "Website Contact Form";
$Name = Trim(stripslashes($_POST['name']));
$Location = Trim(stripslashes($_POST['location']));
$Phone = Trim(stripslashes($_POST['phone']));
$Email = Trim(stripslashes($_POST['email']));
$Comments = Trim(stripslashes($_POST['comments']));
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Location: ";
$Body .= $Location;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $Phone;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $Email;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $Comments;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
// redirect to success page
print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
?>
This question comes up quite a bit.
There is a strong possibility that the mail client (in this case outlook) is configured to filter messages that lack proper headers. This could be at the client point or at the server connection at smtp time. The main thrust of the issue is that the basic php mail() core function is almost universally mistrusted due to its potential for abuse by spammers.
You should try using a library like PHPMailer to help guide you to setting the reply-to and other headers properly.
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.
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)