PHP form mail and register globals - global

I have a form and php processing file, and everything seems to be working fine except that the user-entered variables are not showing up in the emailed form results. From the research I've done (I'm beginner PHP), I'm guessing it's because my script uses HTTP_POST_VARS and my client's server has globals turned off? They recently switched from Godaddy Windows to Godaddy Linux hosting.
This is my processing file:
<?php
// where is your config file stored?
include ("ajaxSubmit.php");
// CLIENT INFORMATION
$Contactname = $HTTP_POST_VARS['Contactname'];
$email = $HTTP_POST_VARS['email'];
$Contacttitle = $HTTP_POST_VARS['Contacttitle'];
$Business = $HTTP_POST_VARS['Business'];
$Address = $HTTP_POST_VARS['Address'];
$City = $HTTP_POST_VARS['City'];
$State = $HTTP_POST_VARS['State'];
$Zip = $HTTP_POST_VARS['Zip'];
$Phone = $HTTP_POST_VARS['Phone'];
$Fax = $HTTP_POST_VARS['Fax'];
$product_desc = $HTTP_POST_VARS['product_desc'];
$delivery = $HTTP_POST_VARS['delivery'];
$sku = $HTTP_POST_VARS['sku'];
$annualturns = $HTTP_POST_VARS['annualturns'];
$seasonal = $HTTP_POST_VARS['seasonal'];
$minmaxpallet = $HTTP_POST_VARS['minmaxpallet'];
$avgpalletval = $HTTP_POST_VARS['avgpalletval'];
$avgpalletwt = $HTTP_POST_VARS['avgpalletwt'];
$maxpalletht = $HTTP_POST_VARS['maxpalletht'];
$casesperpallet = $HTTP_POST_VARS['casesperpallet'];
$unitweight = $HTTP_POST_VARS['unitweight'];
$reqlotnumctrl = $HTTP_POST_VARS['reqlotnumctrl'];
$freightclass = $HTTP_POST_VARS['freightclass'];
$hazardclass = $HTTP_POST_VARS['hazardclass'];
$barcodes = $HTTP_POST_VARS['barcodes'];
$avgupsfedex = $HTTP_POST_VARS['avgupsfedex'];
$avgorderweight = $HTTP_POST_VARS['avgorderweight'];
$ordersending = $HTTP_POST_VARS['ordersending'];
$custpickups = $HTTP_POST_VARS['custpickups'];
$flatfiles = $HTTP_POST_VARS['flatfiles'];
$shrinkwrap = $HTTP_POST_VARS['shrinkwrap'];
$repack = $HTTP_POST_VARS['repack'];
$specialreq = $HTTP_POST_VARS['specialreq'];
// MODIFY THE FOLLOWING SECTION
// your name
$recipientname = "Company X";
// your email
$recipientemail = "email#email.com";
// subject of the email sent to you
$subject = "Quote Request for $recipientname";
// send an autoresponse to the user?
$autoresponse = "yes";
// subject of autoresponse
$autosubject = "Thank you for your mail!";
// autoresponse message
$automessage = "Thanks for the message. We've successfully received your quote request and will get back to you shortly.";
// thankyou displayed after the user clicks "submit"
$thanks = "Thank you for contacting us. We will get back to you as soon as possible.";
// END OF NECESSARY MODIFICATIONS
// format message
$message = "Online-Form Response for $recipientname:
<br>
Contact Name: $Contactname
<br>
Business: $Business
<br>
Email: $email
<br>
Address: $Address
<br>
City: $City
<br>
State: $State
<br>
Zip: $Zip
<br>
Phone: $Phone
<br>
Fax: $Fax
<br>
<br>
<br>
Describe your product(s): $product_desc
<br>
How will your product be delivered?: $delivery
<br>
How many SKU's (items): $sku
<br>
How many turns per year?: $annualturns
<br>
Are your products seasonal?: $seasonal
<br>
Indicate minimum and Maximum pallet levels: $minmaxpallet
<br>
Average value per pallet: $avgpalletval
<br>
Weight of a typical pallet: $avgpalletwt
<br>
Maximum pallet stacking height: $maxpalletht
<br>
Cases per pallet? Or average case size?: $casesperpallet
<br>
Weight of each unit?: $unitweight
<br>
Do you require lot number control?: $reqlotnumctrl
<br>
What freight class?: $freightclass
<br>
Is the product hazardous? If so, what classifications?: $hazardclass
<br>
<br>
<br>
Do you need custom Barcodes made?: $barcodes
<br>
What is the average number of orders shipped via UPS/Fedex?: $avgupsfedex
<br>
What is the average order size in weight?: $avgorderweight
<br>
What is the average number of lines per order?: $avgorderlines
<br>
Will your orders be sent via E-mail, FAX, or other?: $ordersending
<br>
Will you have customer pick ups, and how often?: $custpickups
<br>
Can your company e-mail us flat files?: $flatfiles
<br>
Do your orders need to be shrink wrapped?: $shrinkwrap
<br>
Do you need repackaging?: $repack
<br>
Are there any special requirements that your company may have?: $specialreq
<br>";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'From: Company X <email#email.com>' . "\r\n";
// send mail and print success message
mail($recipientemail, $subject, $message, $headers);
if($autoresponse == "yes") {
$autosubject = stripslashes($autosubject);
$automessage = stripslashes($automessage);
mail($email,"$autosubject","$automessage","From: $recipientname <$recipientemail>");
}
echo "<script language=\"JavaScript\" type=\"text/JavaScript\"> window.location.href = \"thanks_quote.php\";</script>";
?>
EDIT: I tested on another server (with globals on), and the form worked fine, but I'm not sure how to rewrite my script so that it does not rely on POST?

The HTTP_POST_VARS is now deprecated. Also register_globals is deprecated in 5.3.0 and above. So use $_POST instead of HTTP_POST_VARS.
Also, instead of last line:
echo "<script language=\"JavaScript\" type=\"text/JavaScript\"> window.location.href = \"thanks_quote.php\";</script>";
to redirect to another page, use:
header('Location: thanks_quote.php');

Related

Two contact forms, send to two different email addresses

I got two contact forms on my website. On in the contact section, and one in the careers section. I want to receive both forms in different email adresses.
<?php
include_once('class.phpmailer.php');
$mail = new PHPMailer;
$mail->setFrom('adres1','test');
$mail->Subject = 'Contactverzoek via careerspagina.';
$html = "Er is een contactverzoek gedaan via de careerspagina.<br>";
$html .= "<br>";
$html .= "<b>Naam:</b> " . $_POST['name']."<br>";
if(isset($_POST['lastname'])) {
$html .= '<b>Achternaam: </b> ' . $_POST['lastname']."<br>";
}
$html .= "<b>E-mail:</b> " . $_POST['email']."<br>";
if(isset($_POST['telefoon'])) {
$html .= '<b>Telefoon: </b> ' . $_POST['telefoon']."<br>";
}
if(isset($_POST['onderwerp'])) { //FIX NOG!!!
$html .= '<b>Onderwerp: </b> ' . $_POST['onderwerp']."<br>";
}
if(isset($_POST['Werkervaring'])) {
$html .= '<b>Werkervaring: </b> ' . $_POST['Werkervaring']."<br>";
}
if(isset($_POST['Functie'])) {
$html .= '<b>Functie: </b> ' . $_POST['Functie']."<br>";
}
if(isset($_POST['Opleidingsniveaus'])) {
$html .= '<b>Opleidingsniveaus: </b> ' . $_POST['Opleidingsniveaus']."<br>";
}
if(isset($_POST['comment'])) {
$html .= '<b>Bericht: </b> ' . $_POST['comment']."<br>";
}
$html .= "<br>";
if (isset($_FILES['resume']) &&
$_FILES['resume']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['resume']['tmp_name'],
$_FILES['resume']['name']);
}
if (isset($_FILES['letter']) &&
$_FILES['letter']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['letter']['tmp_name'],
$_FILES['letter']['name']);
}
$mail->msgHTML($html);
$mail->addAddress('adres1', 'Info ');
$mail->addBCC('adres1', 'Test ');
if(!$mail->send())
{
echo "0";
}
else
{
echo "1";
}
This is my code, and everything seems to work.
So once again. I want to keep sending this contact form to email A. But There needs to be made and else statement which sends the other contact form to email B.
i'm very new to PHP. Excuse me if i'm not clear.
One simple solution is to send a form parameter indicating which email address should be used. Then you check the POST variable for that parameter in an if statement and set the correct email address to be used.
$to = "forma#example.com";
if($_POST['form'] === "formB") {
$to = "formb#example.com";
}
$mail->addAddress($to, 'Recipient name');
Add hidden inputs in your forms named "form" and set the value to either "formA" or "formB":
<input type="hidden" name="form" value="formA">
Do not set the receiving email address in the form and use that since it can easily be abused to send spam from your server.

php auto sending mail from database?

php auto send mail at time and have setting?
i want create email and save database
at time email auto send to email
ex:i setting at 8:00 PM
Send email1 (to,subject1,message1),send email2(to,subject2,message2)....
Because i use database mysql so, i want auto send subject + message if status =0
status =0 is no send, status =1 is old send.
Please help.
Thanks.
You would need to use a cron job to visit a page:
0 20 * * * curl http://yourwebsite.com/emailscript.php
^Fires off at the 0 minute, of the 20th hour (8:00pm), of every day, of every week, of every month.
contents of emailscript.php:
$to = "email#email.com";
$subject = "Cron Job HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags and is a test of the cron jobs!</p>
</body>
</html>
";
// 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";
// More headers
$headers .= 'From: email#yoursite.com <email#yoursite.com>' . "\r\n";
mail($to,$subject,$message,$headers);

properly setting email subject line delivered from email form

I have a email form for my website but here is the issue: when i receive an email, the subject line in my inbox shows whatever the user inputted as subject in the form. id like to override that so that whenever an email comes in. the subject in the email header is always "an inquiry from your website". In the message body, sure i don't mind their specific subject they entered but when I receive an email, id like consistency in my inbox.
this is the current code:
<?php session_start();
if(isset($_POST['Submit'])) { if( $_SESSION['chapcha_code'] == $_POST['chapcha_code'] && !empty($_SESSION['chapcha_code'] ) ) {
$youremail = 'xxxxxxxxx';
$fromsubject = 'An inquiry from your website';
$title = $_POST['title'];
$fname = $_POST['fname'];
$lname = $_POST['lname'];
$mail = $_POST['mail'];
$address = $_POST['address'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$country = $_POST['country'];
$phone = $_POST['phone'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "From: $nome <$mail>\r\n";
$to = $youremail;
$mailsubject = 'Message received from'.$fromsubject.' Contact Page';
$body = $fromsubject.'
The person that contacted you is '.$fname.' '.$lname.'
Address: '.$address.'
'.$city.', '.$zip.', '.$country.'
Phone Number: '.$phone.'
E-mail: '.$mail.'
Subject: '.$subject.'
Message:
'.$message.'
|---------END MESSAGE----------|';
echo "Thank you for inquiring. We will contact you shortly.<br/>You may return to our <a href='/index.html'>Home Page</a>";
mail($to, $subject, $body, $headers);
unset($_SESSION['chapcha_code']);
} else {
echo 'Sorry, you have provided an invalid security code';
}
} else {
echo "You must write a message. </br> Please visit our <a href='/contact.html'>Contact Page</a> and try again.";
}
?>
It appears as though you have set a variable called $subject elsewhere.
$subject = $_POST['subject'];
and then use that same variable to send your mail.
mail($to, $subject, $body, $headers);
Try creating another variable for the second use or changing it prior to suit your needs.

PHP mail function not working

I do not think the problem lies with the mail function code, but with my aproach of the $_SESSION variables. I have a form consisting of 5 pages, the fifth being a preview page. Upon the final submission, on the preview page, i want the entire $_SESSION data to be sent to two different email adresses.
I am displaying the data on the preview page as follows:
<?php
//retrieve session data
echo "<b> Varname: </b>". $_SESSION['varname'];
?>
in a form with method="post" and action="mail.php".
In the mail.php, i start the session, and then:
$_SESSION['email'] = $mail;
$_SESSION['varname'] = $varname;
$email_from = 'mail#company.de';
$email_subject = "Mail";
$email_body = "You have submitted the following data: $inhalt.\n";
$to = "mymail#company.de, $mail";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
Upon submitting the form the page goes to blank. What exactly am i doing wrong?
I managed to solve the problem in the end, as follows:
$email_from = 'mail#company.de';
$email_subject = "Mail";
$to = ("myadress#work.de," . $_SESSION['email'] . "");
mail($to,"Form submission","Form data:
Inhalt: " . $_SESSION['inhalt1'] . "
");
As I said in the question, the problem was my aproach of the $_SESSION variables. Instead of $_SESSION['varname'] = $varname, i just went directly with . $_SESSION['varname'] .ยด.

PHP mail to variable

I've searched and searched for something similar, but i think i'm not doing it right. So i will ask a question. This is very basic. My problem is as follows:
I have a multi-page form, consisting of 4 pages + 1 preview page. On the preview page, upon submitting i want the entire form data to be sent to 2 different mail adresses. One standard, and the other one, the one that the user has submitted.
So i have:
<?php
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$message = $_POST['message'];
?>
<?php
$email_from = 'mail#company.com';
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $name.\n".
"Here is the message:\n $message".
$to = "yourname#yourwebsite.com, $email /n";
$headers = "From: Company";
mail($to,$email_subject,$email_body,$headers);
?>
How should I insert the submitted $email variable in order for it to work?
Remove the \n
$to = 'yourname#yourwebsite.com,' . $visitor_email;
According to the mail() function documentation the $to parameter will take a comma-separated list of addresses as you have attempted, but should have no line break at the end.
Also, your variable is $visitor_email, rather than $email.
$to = "yourname#yourwebsite.com, $visitor_email";
You might also consider adding the visitor's email as a CC or BCC rather than the TO address. In that case, add it as a CC or BCC header (separated by \r\n), but you need to be cautious to be sure that the address is an email address and contains no line break characters which could be used for header injection.
// The From should be an email address
$headers = "From: company#example.com\r\n";
$headers .= "CC: $visitor_email;