I know the title is weird I cant for the life of me phrase it well lol.
I have done searches with multiple ways of phrasing the question and nothing shows up for this.
I have the email scripting working on the website im building and its fantastic! but when i edited the mail code to add extra message lines its made the sequence go wrong.
here is the code im using for the email message area:
<?php
require_once "Mail.php";
// load the variables form address bar
$name = $_REQUEST["name"];
$subject = 'Customer Feedback';
$message = $_REQUEST["message"];
$from = $_REQUEST["from"];
$compname = $_REQUEST["companyName"];
$ph = $_REQUEST["phone"];
$acp = $_REQUEST['allowCommentPublish'];
$marketing = $_REQUEST['incmarketing'];
$verif_box = $_REQUEST["verif_box"];
// Checking the check boxes and marking as appropriate
if(isset($_POST['allowCommentPublish']))
{
$acp = 'Yes';
}
else
{
$acp = 'No';
}
if(isset($_POST['incmarketing']))
{
$marketing = 'Yes';
}
else
{
$marketing = 'No';
}
// Optional data checker
if($compname == '')
{
$compname = 'N/A';
}
if($ph == '')
{
$ph = 'N/A';
}
// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$message = stripslashes($message);
$subject = stripslashes($subject);
$acp = stripcslashes($acp);
$marketing = stripcslashes($marketing);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'])
{
// if verification code was correct send the message and show this page
$ToEmail = "email#email.com";
$message = "Name: ".$name."\n".$message;
$message = "From: ".$from."\n".$message;
$message = "Comments: ".$message."\n".$message;
$message = "Allow feedback to be Published: ".$acp."\n".$message;
$message = "[ OPTIONAL DATA ]"."\n".$message;
$message = "Company Name: ".$compname."\n".$message;
$message = "Phone Number: ".$ph."\n".$message;
$message = "Allow extra Marketing? ".$marketing."\n".$message;
$headers = array ('From' => $from,
'To' => $ToEmail,
'Subject' => 'Feedback: '.$subject);
$smtp = Mail::factory('smtp', array ('host' => 'smtp.vic.exemail.com.au', 'auth' => false));
$mail = $smtp->send($ToEmail, $headers, $message);
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
header("Location: /feedback_sent.php");
exit;
}
else
{
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
In my mind this should spit out the message body as this:
Name: name here
From: Email address
Comments: Message here
Allow feedback to be published: response
[ OPTIONAL DATA ]
Company Name: Company
Phone Number: Phone
Allow extra Marketing:
This should be how its seen in the email right?
What im actually getting is this:
Allow feedback to be Published: response
[ OPTIONAL DATA ]
Company Name: company
Phone Number: phone
Allow extra Marketing? Response
From: Email address
Name: name here
Comments: Message here
Is this normal? or have i inadvertently snuffed it somewhere along the lines and its messing with my head as payment?
Thanks for any help on this.
EDIT: Updated code.
<?php
// -----------------------------------------
// The Web Help .com
// -----------------------------------------
// remember to replace your#email.com with your own email address lower in this code.
require_once "Mail.php";
// load the variables form address bar
$name = $_REQUEST["name"];
$subject = 'Customer Feedback';
$comment = $_REQUEST["message"];
$from = $_REQUEST["from"];
$compname = $_REQUEST["companyName"];
$ph = $_REQUEST["phone"];
$acp = $_REQUEST['allowCommentPublish'];
$marketing = $_REQUEST['incmarketing'];
$verif_box = $_REQUEST["verif_box"];
// Checking the check boxes and marking as appropriate
if(isset($_POST['allowCommentPublish']))
{
$acp = 'Yes';
}
else
{
$acp = 'No';
}
if(isset($_POST['incmarketing']))
{
$marketing = 'Yes';
}
else
{
$marketing = 'No';
}
// Optional data checker
if($compname == '')
{
$compname = 'N/A';
}
if($ph == '')
{
$ph = 'N/A';
}
// remove the backslashes that normally appears when entering " or '
$name = stripslashes($name);
$comment = stripslashes($comment);
$subject = stripslashes($subject);
$acp = stripcslashes($acp);
$marketing = stripcslashes($marketing);
$from = stripslashes($from);
// check to see if verificaton code was correct
if(md5($verif_box).'a4xn' == $_COOKIE['tntcon'])
{
// if verification code was correct send the message and show this page
$ToEmail = "jim#digital2go.com.au";
$message = "Name: ".$name."\n".$message;
$message .= "From: ".$from."\n".$message;
$message .= "Comments: ".$comment."\n".$message;
$message .= "Allow feedback to be Published: ".$acp."\n".$message;
$message .= "[ OPTIONAL DATA ]"."\n".$message;
$message .= "Company Name: ".$compname."\n".$message;
$message .= "Phone Number: ".$ph."\n".$message;
$message .= "Allow extra Marketing? ".$marketing."\n".$message;
$headers = array ('From' => $from,
'To' => $ToEmail,
'Subject' => 'Feedback: '.$subject);
$smtp = Mail::factory('smtp', array ('host' => 'smtp.vic.exemail.com.au', 'auth' => false));
$mail = $smtp->send($ToEmail, $headers, $message);
// delete the cookie so it cannot sent again by refreshing this page
setcookie('tntcon','');
header("Location: /feedback_sent.php");
exit;
}
else
{
// if verification code was incorrect then return to contact page and show error
header("Location:".$_SERVER['HTTP_REFERER']."?subject=$subject&from=$from&message=$message&wrong_code=true");
exit;
}
?>
Make your message "continue" in the order you wish by doing this:
$message = "Name: ".$name."\n".$message;
$message .= "From: ".$from."\n".$message;
$message .= "Comments: ".$message."\n".$message;
$message .= "Allow feedback to be Published: ".$acp."\n".$message;
$message .= "[ OPTIONAL DATA ]"."\n".$message;
$message .= "Company Name: ".$compname."\n".$message;
$message .= "Phone Number: ".$ph."\n".$message;
$message .= "Allow extra Marketing? ".$marketing."\n".$message;
Related
I want to send mails using this PHP MAILING script but through SMTP and not through sendmail because my host rejects all emails as spam and I don't check my spam folder as its heavy loaded with spam emails daily.
I just want to know where to put the code which will use my SMTP logins to send mails using this php script instead of using sendmail/
I tried adding some things like
$host = "smtp.gmail.com";
$port = "587";
$username = "testtest#gmail.com";
$password = "testtest";
But these didn't worked, actually it broke the whole code itself,
Edit: I also tried adding this, reading an answer from another answered question here, and it also broke the code itself but didn't work.
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'johndoe#gmail.com',
'password' => 'passwordxxx'
Original Code
<?php
$errorMSG = "";
// NAME
if (empty($_POST["name"])) {
//only shows if prevent default fails (js in index.html)
$errorMSG = "Name is required ";
} else {
$name = $_POST["name"];
}
// EMAIL
if (empty($_POST["email"])) {
//only shows if prevent default fails (js in index.html)
$errorMSG .= "E-mail is required ";
} else {
$email = $_POST["email"];
}
// MESSAGE
if (empty($_POST["message"])) {
//only shows if prevent default fails (js in index.html)
$errorMSG .= "Message is required ";
} else {
$message = $_POST["message"];
}
// change this to fit !
$EmailTo = "demo#domain.com";
$Subject = "New Message from MENTOR";
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Message: ";
$Body .= $message;
$Body .= "\n";
// send email
$success = mail($EmailTo, $Subject, $Body, "From:".$email);
// redirect to success page
if ($success && $errorMSG == ""){
echo "success";
}else{
if($errorMSG == ""){
echo "Somethin went wrong...";
} else {
echo "An error has ocurred!";
//echo $errorMSG; Enable if you want full details of php error
}
}
?>
I have a simple form with a security question to prevent spamming.
link to my webpage with the form in question http://ddry.co.uk/contact_us.html.
I want to be able to output an html page if a user inputs an incorrect answer rather than just plain text.
I have a redirect to another html file if the form is successful at the bottom of my php script. looking at other forums someone suggested using readfile("contact-failed.html#fail"); to display the html; However I'm not entirely sure where to put the code for the redirect of an incorrect answer. I'm new to PHP, so if someone is able to explain what I'm doing wrong that would great. Or alternately if somone has a better spam filter code that would be great also Thanks in advance.
html code of anti spam
php file for post.
----- UPDATE --------
I think what i'm after is an if, else statement?
after researching I have altered my code to include an else statement; However due to my lack of PHP knowledge I'm still getting a blank screen instead of my error redirect html page, which is shown at the bottom of my php code.
Question: how can I properly configure the if, else statement so if the anti-spam result is wrong (doesn't equal to 12) then proceed to contact-failed.html?
Thanks in advance
<?php
// Email address verification
function isEmail($clientEmail) {
return filter_var($clientEmail, FILTER_VALIDATE_EMAIL);}
if($_POST) {
// Enter the email where you want to receive the message
$myemail = 'info#ddry.co.uk';
$name = addslashes(trim($_POST['name']));
$clientEmail = addslashes(trim($_POST['email']));
$subject = addslashes(trim($_POST['phone']));
$phone = addslashes(trim($_POST['phone']));
$message = addslashes(trim($_POST['message']));
$antispam = addslashes(trim($_POST['antispam']));
$array = array('nameMessage' => '','emailMessage' => '', 'phoneMessage' => '', 'messageMessage' => '', 'antispamMessage' => '');
if(!isEmail($clientEmail)) {
$array['nameMessage'] = 'Empty name';
}
if(!isEmail($clientEmail)) {
$array['emailMessage'] = 'Invalid email!';
}
if($phone == '') {
$array['phoneMessage'] = 'Empty phone number!';
}
if($message == '') {
$array['messageMessage'] = 'Empty message!';
}
if($antispam != '12') {
$array['antispamMessage'] = 'Incorrect Answer!';
}
if(isEmail($clientEmail) && $clientEmail != '' && $message != '' && $antispam == '12') {
// Send email
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $clientEmail\n Message: \n $message\n Phone: $phone";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $clientEmail";
mail($to,$email_subject,$email_body,$headers);
echo json_encode($array);
header('Location: contact-success.html#success');
}
else (isEmail($clientEmail) && $clientEmail != '' && $message != '' && $antispam !== '12'){
echo('Location: contact-failed.html#fail');}
?>
Why not try something simple like this ?
function isEmail($clientEmail) {
return filter_var($clientEmail, FILTER_VALIDATE_EMAIL);
}
if($_POST){
// Enter the email where you want to receive the message
$myemail = 'info#ddry.co.uk';
$name = addslashes(trim($_POST['name']));
$clientEmail = addslashes(trim($_POST['email']));
$subject = addslashes(trim($_POST['phone']));
$phone = addslashes(trim($_POST['phone']));
$message = addslashes(trim($_POST['message']));
$antispam = addslashes(trim($_POST['antispam']));
if($antispam == '12' && isEmail($clientEmail) && $phone != '' && $message != '' ){
$to = $myemail;
$email_subject = "Contact form submission: $name";
$email_body = "You have received a new message. ".
" Here are the details:\n Name: $name \n ".
"Email: $clientEmail\n Message: \n $message\n Phone: $phone";
$headers = "From: $myemail\n";
$headers .= "Reply-To: $clientEmail";
mail($to,$email_subject,$email_body,$headers);
echo json_encode($array);
header('Location: contact-success.html#success');
}
else {
header('Location: contact-failed.html#fail');
}
My question is why you need to show another page instead of the error message in the contact form. You are redirecting to another page on success, the same can be applied on error also, you can redirect to another html page to show different version .
There are a lot of other posts about this. I have gone through several and tried arrays and inputting emails in the $to field and the like but my form keeps only sending if I specify one email. What am I doing wrong? I'm a PHP noob too.
<?php
// EVALUATION FORM
$your_email = 'email1#address.com, email2#address.com';
session_start();
$errors = '';
$name = '';
$visitor_email = '';
$phone = '';
if (isset($_POST['submit'])) {
$name = $_POST['name'];
$visitor_email = $_POST['email'];
$phone = $_POST['phone'];
///------------Do Validations-------------
if (empty($name) || empty($visitor_email)) {
$errors .= "\n Form was not submitted. Please fill out all the fields. ";
}
if (IsInjected($visitor_email)) {
$errors .= "\n Bad email value!";
}
if (empty($_SESSION['6_letters_code']) || strcasecmp($_SESSION['6_letters_code'], $_POST['6_letters_code']) != 0) {
//Note: the captcha code is compared case insensitively.
//if you want case sensitive match, update the check above to
// strcmp()
$errors .= "\n The captcha code does not match!";
}
if (empty($errors)) {
//send the email
$to = $your_email;
$subject = "Free Injury Evaluation form submission from Northwest Injury Centers";
$from = $your_email;
$ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : '';
$body = "$name submitted the Free Injury Evaluation form:\n\n" . "Name: $name\n" . "Email: $visitor_email \n" . "Phone: $phone \n" . "IP: $ip\n";
$headers = "From: $from \r\n";
$headers .= "Reply-To: $visitor_email \r\n";
mail($to, $subject, $body, $headers);
header('Location: thankyou.php');
}
}
// Function to validate against any email injection attempts
function IsInjected($str)
{
$injections = array(
'(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if (preg_match($inject, $str)) {
return true;
} else {
return false;
}
}
?>
You can provide multiple recipients, however you can only provide one sender. Since you are using $your_email both for $to and $from, you're trying to send an email with multiple senders.
This will work:
$email_to = "jhewitt#amleo.com,some#other.com,yet#another.net";
Fore readability sake in the code use an array and implode it to a comma separated string:
$recipients = array(
"youremailaddress#yourdomain.com",
// more emails
);
$email_to = implode(',', $recipients); // your email address
$email_subject = "Contact Form Message"; // email subject line
$thankyou = "thankyou.htm"; // thank you page
You can add cc to your mail header,
$headers .= 'Cc: someemail#domain.com' . "\r\n";
This will send a copy to the above mentioned email along with to email address.
We have a PHP form on our website that has worked for years. When users fill the form out in sends us the details, and sends them an email and then re-directs the user to a "thank-you" page. However, if a user puts their email address as #gmail.com the form fails to send, it doesnt show the thank-you page.
This is really bizarre. We are using PHPMailer and validate if the form has been sent using:
if($mail->Send()) {
$mailsent = true;
If a user enters #hotmail.com or at #yahoo.com everything is fine. But enter #gmail.com and $mailsent is always false.
In this situation where does the problem lye? It seems to me that our web hosts SMTP connection to Gmail is failing. Would this seem right?
Here is the code:
<?php
error_reporting(E_ALL);
ini_set("display_errors", 1);
$name = '';
$email = '';
$mailsent = false;
$referer = '';
if(isset($_POST['name'])){
include('phpmailer/class.phpmailer.php');
$name = $_POST['name'];
$email = $_POST['email'];
$subject = 'Quote request from ' . $name;
$body = 'A quote request has been received from a user with following details:' . "\n\n" .
"Name: $name \n" .
"Email: $email \n" .
"----------------------------------------------------\n\n" .
"Place: UK".
$body .= "\n----------------------------------------------------\n\n";
$body .= "Refering: ".$referer." \n";
$mail = new PHPMailer();
$mail->Subject = $subject;
$mail->From = $email;
$mail->FromName = $name;
$mail->Body = $body;
$mail->AddAddress("dean#example.com", "Example");
if($mail->Send()) {
$mailsent = true;
} else {
$error[] = 'There was some error. Please try later.';
}
}
?>
Been struggling very much with only sending the fields that people fill in. It is a simple order form with text fields. But I want it so that only those fields that are field in get sent to my alert email. I tried the codes on the topic "PHP form: Success email with only filled fields" but my php script crashes when I do. Here is my code before I tried any modifying. This email fine only that it includes all fields I only want the one filled in. Please help I am a total noob in php. All help appreciated.
<?
$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$silver_name_badges = $_POST['silver_name_badges'];
$coffee_mug = $_POST['coffee_mug'];
$plastic_bag = $_POST['plastic_bag'];
$paper_bag = $_POST['paper_bag'];
$candy = $_POST['candy'];
$moist_towlette = $_POST['moist_towlette'];
$notepad_and_pen = $_POST['notepad_and_pen'];
$tuck_box = $_POST['tuck_box'];
$red_tie = $_POST['red_tie'];
$cap = $_POST['cap'];
$name = $_POST['Attention_To'];
$red_lanyard = $_POST['red_lanyard'];
$white_lanyard = $_POST['white_lanyard'];
$green_lanyard = $_POST['green_lanyard'];
$black_lanyard = $_POST['black_lanyard'];
$LC2415 = $_POST['LC2415'];
$FOM_2NTRI = $_POST['FOM_2NTRI'];
$ASTRO_165WMT = $_POST['ASTRO_165WMT'];
$FOL_AJ3015 = $_POST['FOL_AJ3015'];
$ACIES_NT = $_POST['ACIES_NT'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.ama-japan.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ravila#ama.com');
// Set parameters of the email
$to = "joe#ama.com";
$subject = "Ama Promo Items Ordered";
$from = " jurt#ama.com";
$headers = "From: $from";
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
if($Phone)
$Body .= "Phone: "; $Body .= $Phone; $Body .= "\n";
$message .="
Silver Name Badges: $silver_name_badges\n
Coffee Mug: $coffee_mug\n
Plastic Literature Bag: $plastic_bag\n
Amada Bag: $paper_bag\n
Candy: $candy\n
Notepad & Pen: $notepad_and_pen\n
Tuck Box: $tuck_box\n
Amada Tie: $red_tie\n
Candy: $candy\n
Moist Towlette: $moist_towlette\n
Cap: $cap\n
Lanyard:
Red - $red_lanyard
White - $white_lanyard
Green - $green_lanyard
Black - $black_lanyard\n
Rock Glass:
LC2415 - $LC2415
FOM 2NTRI - $FOM_2NTRI
ASTRO 165WMT - $ASTRO_165WMT
FOL AJ3015 - $FOL_AJ3015
ACIES NT - $ACIES_NT";
// Mail function that sends the email.
mail($to,$subject,$message,$headers);
header('Location: thank-you.html');
?>
The errors might be related to unset POST variables.
How about a loop? It will only use what is sent over.
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " ". str_replace('_',' ',$fieldName) .": $fieldValue\n";
}
OK I added this and worked great. How the email comes back with the field name with underscores. How to send without underscores?:
<?php
//$silver_name_badges = !empty($_POST['silver_name_badges']) ? ($_POST['silver_name_badges'])) : false;
$SilverNameBadges = $_POST['Silver Name Badges'];
$CoffeeMug = $_POST['coffee_mug'];
$PlasticLiteratureBag = $_POST['plastic_bag'];
$paper_bag = $_POST['paper_bag'];
$candy = $_POST['candy'];
$moist_towlette = $_POST['moist_towlette'];
$notepad_and_pen = $_POST['notepad_and_pen'];
$tuck_box = $_POST['tuck_box'];
$red_tie = $_POST['red_tie'];
$cap = $_POST['cap'];
$name = $_POST['Attention_To'];
$red_lanyard = $_POST['red_lanyard'];
$white_lanyard = $_POST['white_lanyard'];
$green_lanyard = $_POST['green_lanyard'];
$black_lanyard = $_POST['black_lanyard'];
$LC2415 = $_POST['LC2415'];
$FOM_2NTRI = $_POST['FOM_2NTRI'];
$ASTRO_165WMT = $_POST['ASTRO_165WMT'];
$FOL_AJ3015 = $_POST['FOL_AJ3015'];
$ACIES_NT = $_POST['ACIES_NT'];
// Please specify your Mail Server - Example: mail.yourdomain.com.
ini_set("SMTP","mail.amada-america.com");
// Please specify an SMTP Number 25 and 8889 are valid SMTP Ports.
ini_set("smtp_port","25");
// Please specify the return address to use
ini_set('sendmail_from', 'ravila#amada.com');
// Set parameters of the email
$to = "ravila#amada.com";
$subject = "Amada Promo Items Ordered";
$from = " nostrowski#amada.com";
$headers = "From: $from";
$message = "";
$message .= "Order has been placed. Attn to: $name .\n
Items:\n";
foreach ($_POST as $fieldName => $fieldValue){
if (!empty($fieldValue))
$message .= " $fieldName: $fieldValue\n";
}
// Mail function that sends the email.
mail($to,$subject,$message,$headers);
header('Location: thank-you.html');
?>