Two forms with alert-box success, one works the other doesn't - forms

I got an html template with a contact form from a site and I love it. I edited it to send the data to me, and it works. Once the user hits submit, the alert-box comes across the page indicating the message was sent. I need another form so I copied the original one, changed the name, edited the forms with the fields I need, copied the php file to one with a name that corresponds to my new form. The form works, I get the data however, instead of getting the alert-box, the page goes to a blank page with the url of the php file and the message "Thank you! We have received your message." I don't know what's wrong and why the alert box isn't working. Any help would be appreciated.
<?php
//Retrieve form data.
//GET - user submitted data using AJAX
//POST - in case user does not support javascript, we'll use POST instead
$full_name = ($_GET['full_name']) ? $_GET['full_name'] : $_POST['full_name'];
$h_address = ($_GET['h_address']) ?$_GET['h_address'] : $_POST['h_address'];
$h_city = ($_GET['h_city']) ?$_GET['h_city'] : $_POST['h_city'];
$h_state = ($_GET['h_state']) ?$_GET['h_state'] : $_POST['h_state'];
$h_zipcode = ($_GET['h_zipcode']) ?$_GET['h_zipcode'] : $_POST['h_zipcode'];
$h_phone_n = ($_GET['h_phone_n']) ?$_GET['h_phone_n'] : $_POST['h_phone_n'];
$c_phone_n = ($_GET['c_phone_n']) ?$_GET['c_phone_n'] : $_POST['c_phone_n'];
$h_email = ($_GET['h_email']) ?$_GET['h_email'] : $_POST['h_email'];
$w_fon_n1 = ($_GET['w_fon_n1']) ?$_GET['w_fon_n1'] : $_POST['w_fon_n1'];
$w_email = ($_GET['w_email']) ?$_GET['w_email'] : $_POST['w_email'];
$Voice = ($_GET['Voice']) ?$_GET['Voice'] : $_POST['Voice'];
$First_Second = ($_GET['First_Second']) ?$_GET['First_Second'] : $_POST['First_Second'];
$notify_by = ($_GET['notify_by']) ?$_GET['notify_by'] : $_POST['notify_by'];
$Experience = ($_GET['Experience']) ?$_GET['Experience'] : $_POST['Experience'];
//flag to indicate which method it uses. If POST set it to 1
if ($_POST) $post=1;
//Simple server side validation for POST data, of course, you should validate the email
if (!$full_name) $errors[count($errors)] = 'Please enter your full name.';
if (!$h_address) $errors[count($errors)] = 'Please enter your street address.';
if (!$h_city) $errors[count($errors)] = 'Please enter your city.';
if (!$h_state) $errors[count($errors)] = 'Please enter your state.';
if (!$h_zipcode) $errors[count($errors)] = 'Please enter your zipcode.';
if (!$h_phone_n) $errors[count($errors)] = 'Please enter your home phone.';
if (!$c_phone_n) $errors[count($errors)] = 'Please enter your cell phone.';
if (!$h_email) $errors[count($errors)] = 'Please enter your email.';
if (!$Voice) $errors[count($errors)] = 'Please enter your voice part.';
if (!$First_Second) $errors[count($errors)] = 'Please enter whether first or second.';
if (!notify_by) $errors[count($errors)] = 'Please enter how we should contact you.';
if (!$Experience) $errors[count($errors)] = 'Please enter your choral experience.';
//if the errors array is empty, send the mail
if (!$errors) {
//recipient - replace your email here
$to = 'mail#email.com';
//sender - from the form
$from = 'MCC Audition Request <webmaster#mendelssohnchoir.com>';
//subject and the html message
$subject = 'MCC Audition Request from ' . $full_name;
$message = 'FullName: ' . $full_name . '<br/><br/>
Address: ' . $h_address . '<br/><br/>
City: ' . $h_city . '<br/><br/>
State: ' . $h_state . '<br/><br/>
Zipcode: ' . $h_zipcode . '<br/><br/>
HPhone: ' . $h_phone_n . '<br/><br/>
HCell: ' . $c_phone_n . '<br/><br/>
HomeEmail: ' . $h_email . '<br/><br/>
WPhone: ' . $w_phone_n . '<br/><br/>
WEmail: ' . $w_email . '<br/><br/>
Voice: ' . $Voice . '<br/><br/>
Voicepart: ' . $First_Second . '<br/><br/>
NotifyBy: ' . $notify_by . '<br/><br/>
Message: ' . nl2br($Experience) . '<br/>';
//send the mail
$result = sendmail($to, $subject, $message, $from);
//if POST was used, display the message straight away
if ($_POST) {
if ($result) echo 'Thank you! We have received your message.';
else echo 'Sorry, unexpected error. Please try again later';
//else if GET was used, return the boolean value so that
//ajax script can react accordingly
//1 means success, 0 means failed
} else {
echo $result;
}
//if the errors array has values
} else {
//display the errors message
for ($i=0; $i<count($errors); $i++) echo $errors[$i] . '<br/>';
echo 'Back';
exit;
}
//Simple mail function with HTML header
function sendmail($to, $subject, $message, $from) {
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
$result = mail($to,$subject,$message,$headers);
if ($result) return 1;
else return 0;
}
?>

Related

page has Too many redirects from mail.php file?

I hope someone can help me. I have a page with a form and then the information
is emailed to me. the code below seems to be redirecting to the same page over and over again. It used to work for years now its not always working.
any help appreciated. Thanks Steve
<?php
//****************************************
//edit here
$senderName = 'WEB';
$senderEmail = 'site#example.com';
$targetEmail = 'contact#sellmydiabeticteststrips.com';
$messageSubject = 'Message from web-site';
$redirectToReferer = true;
$redirectURL = 'contact.html';
//****************************************
// mail content
$ufname = $_POST['ufname'];
$uaddress = $_POST['uaddress'];
$uemail = $_POST['uemail'];
$utel = $_POST['utel'];
$ucity = $_POST['ucity'];
$ustate = $_POST['ustate'];
$uzip = $_POST['uzip'];
$ubrand = $_POST['ubrand'];
$unumber = $_POST['unumber'];
$ucheck = $_POST['ucheck'];
$agree = $_POST['agree'];
// collect interests data
$interestsString = '';
for($i = 0; $i < count($interests); $i++) {
$interestsString .= $interests[$i].($i < count($interests) - 1 ? ', ' : '');
}
// prepare message text
$messageText = 'First Name: '.$ufname."\n".
'Address: '.$uaddress."\n".
'Email: '.$uemail."\n".
'Telephone: '.$utel."\n".
'City: '.$ucity."\n".
'State: '.$ustate."\n".
'Zip: '.$uzip."\n".
'Brand of test strips: '.$ubrand."\n".
'Number of boxes: '.$unumber."\n".
'Check: '.$ucheck."\n".
'Terms and Conditions: '.$agree."\n";
if($interestsString) {
$messageText .= 'Kinderen wonen bij mij: '.$interestsString."\n";
}
// send email
$senderName = "=?UTF-8?B?" . base64_encode($senderName) . "?=";
$messageSubject = "=?UTF-8?B?" . base64_encode($messageSubject) . "?=";
$messageHeaders = "From: " . $senderName . " <" . $senderEmail . ">\r\n"
. "MIME-Version: 1.0" . "\r\n"
. "Content-type: text/plain; charset=UTF-8" . "\r\n";
if (preg_match('/^[_.0-9a-z-]+#([0-9a-z][0-9a-z-]+.)+[a-z]{2,4}$/',$targetEmail,$matches))
mail($targetEmail, $messageSubject, $messageText, $messageHeaders);
// redirect
if($redirectToReferer) {
header("Location: ".#$_SERVER['HTTP_REFERER'].'#sent');
} else {
header("Location: ".$redirectURL);
}
?>

How to reset user password by wordpress rest api

Any one of you know know to send a reset link for lost password by wordpress rest api ? I have been looking into wordpress rest api documentation but I haven't find out anything about it. Maybe someone has done a custom function for that.
I found out a way to do that:
function runRetrivePassword($data)
{
global $wpdb, $wp_hasher;
$user_data = get_user_by('email', $data['email']);
if (!$user_data) return array('result' => false);
do_action('lostpassword_post');
$user_login = $user_data->user_login;
$user_email = $user_data->user_email;
$key = get_password_reset_key($user_data);
$message = __('Someone requested that the password be reset for the following account:') . "\r\n\r\n";
$message .= network_home_url('/') . "\r\n\r\n";
$message .= sprintf(__('Username: %s'), $user_login) . "\r\n\r\n";
$message .= __('If this was a mistake, just ignore this email and nothing will happen.') . "\r\n\r\n";
$message .= __('To reset your password, visit the following address:') . "\r\n\r\n";
$message .= network_site_url("wp-login.php?action=rp&key=$key&login=" . rawurlencode($user_login), 'login');
if (is_multisite())
$blogname = $GLOBALS['current_site']->site_name;
else
$blogname = wp_specialchars_decode(get_option('blogname'), ENT_QUOTES);
$title = sprintf(__('[%s] Password Reset'), $blogname);
$title = apply_filters('retrieve_password_title', $title);
$message = apply_filters('retrieve_password_message', $message, $key);
if ($message && !wp_mail($user_email, $title, $message))
wp_die(__('The e-mail could not be sent.') . "<br />\n" . __('Possible reason: your host may have disabled the mail() function...'));
return array('result' => true);
}
add_action('rest_api_init', function () {
register_rest_route('apiuser/v1', '/forgotpwd/(?P<email>\S+)', array(
'methods' => 'GET',
'callback' => 'runRetrivePassword'
));
});

contact form not sending email to my specific address

I have a php contact form on my website. It sends me email on my normal address. But when I put in the desired mail recipient address in the 'to' section. I do not get any email. What could be the issue??
<?php
if (isset($_POST["submit"])) {
$name = $_POST['name'];
$number = $_POST['number'];
$email = $_POST['email'];
$message = $_POST['message'];
$from = ' Contact Form';
$to = '';
$subject = 'Message from Website contact page ';
$body ="From: $name\n Number: $number\n E-Mail: $email\n Message:\n $message";
// Check if name has been entered
if (!$_POST['name']) {
$errName = 'Please enter your name';
}
if (!$_POST['number']) {
$errNumber = 'Please enter your mobile number';
}
// Check if email has been entered and is valid
if (!$_POST['email'] || !filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
$errEmail = 'Please enter a valid email address';
}
//Check if message has been entered
if (!$_POST['message']) {
$errMessage = 'Please enter your message';
}
// If there are no errors, send the email
if (!$errName && !$errNumber && !$errEmail && !$errMessage ) {
if (mail ($to, $subject, $body, $from)) {
$result='<div class="alert alert-success">Thank You! We will get in touch with you soon.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}
}
?>
can you check this:
$to = "desiredmailID#example.com, yourmailID#example.com";
// 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: noreply#example.com" . "\r\n";
// Check if name has been entered
$errName = '';
if ($_POST['name'] == '') {
$errName = 'Please enter your name';
}
//Other validation messages here...
// If there are no errors, send the email
if ($errName == '' && $errNumber == '' && $errEmail == '' && $errMessage == '' ) {
if (mail ($to, $subject, $body, $headers)) {
$result='<div class="alert alert-success">Thank You! We will get in touch with you soon.</div>';
} else {
$result='<div class="alert alert-danger">Sorry there was an error sending your message. Please try again later.</div>';
}
}

Warning: mail(): SMTP server response: 550 This is a submission only port. You must authenticate before sending mail in

I'm new to PHP and have some problem on my registration form.
The script as below cannot function. And keep error
Warning: mail(): SMTP server response: 550 This is a submission only port. You must authenticate before sending mail in E:\inetpub\abc.com.my\wwwroot\abc_Draft9_190713\processor.php on line 40"Any idea? thank.
<?php
$where_form_is="http://".$_SERVER['SERVER_NAME'].strrev(strstr(strrev($_SERVER['PHP_SELF']),"/"));
$title = $_REQUEST['textfield_1'];
$firstname = $_REQUEST['textfield_2'];
$lastname = $_REQUEST['textfield_3'];
$email = $_REQUEST['textfield_4'];
$mobile = $_REQUEST['textfield_5'];
$interesteddevelopement = $_REQUEST['textfield_6'];
$message = $_REQUEST['textfield_7'];
if (!($firstname && $lastname && $mobile && $email && $interesteddevelopement && $message)) {
?>
<script language = 'javascript'>
alert('Please fill in every required field.');
history.back();
</script>
<?php
exit();
} else {
ini_set("SMTP","mail.abc.com.my");
ini_set("smtp_port","587");
//ini_set('sendmail_from', 'ValidEmailAccount#YourDomain.com');
$headers = "From: $email";
mail("abc#interactive.com.my","abc Website Enquiry Form","
Title : " . $_POST['textfield_1'] . "
First Name : " . $_POST['textfield_2'] . "
Last Name : " . $_POST['textfield_3'] . "
Email : " . $_POST['textfield_4'] . "
Mobile : " . $_POST['textfield_5'] . "
Interested Developement : " . $_POST['textfield_6'] . "
Message : " . $_POST['textfield_7'] . "
",$headers);
include("confirmed.html");
}
?>
php.ini & SMTP= - how do you pass username & password
PHP mail() command does not support authentication. Your options: ...

Redisplaying a form with fields filled in

I need a bit of help with redisplaying a form.
Basically, currently a user will fill out my contact form, the form and it's contents are passed to my verification page, and if the recaptcha was entered correctly it goes to a Thank You page.
When the recaptcha is entered INCORRECTLY, I want to redisplay the contact form with the fields already filled out. How do I do this? (As you'll see below, it currently goes to google on incorrect captcha)
Here is my verification code. Any help would be great:
<?php require('sbsquared.class.php'); ?>
<?php
require_once('recaptchalib.php');
$privatekey = "myprivatekey";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
// What happens when the CAPTCHA was entered incorrectly
header("Location: http://www.google.com"); <--- this is the bit that I want to redisplay the form with fields already filled out.
} else {
$sb = New SBSquared;
$name = $_POST['FullName'];
$post_keys = array_keys($_POST);
$my_db_string = "<table>";
$ip_address = $_SERVER['REMOTE_ADDR'];
foreach($post_keys as $field)
{
if($_POST[$field] != "" && $field != "submit_y" && $field != "submit_x" && $field != "submit_x")
{
$my_db_string .= "<tr><td><b>".$field.":</b></td><td>";
if($field == "Email")
{
$my_db_string .= ''.$_POST['Email'].'';
}
else
{
$my_db_string .= $_POST[$field];
}
$my_db_string .= "</td></tr>";
}
}
$my_db_string .= "<tr><td><b>IP ADDRESS LOGGED: </b></td><td>".$ip_address."</td></tr>";
$my_db_string .= "</table>";
if(get_magic_quotes_gpc() != 1)
{
$my_db_string = addslashes($my_db_string);
$name = addslashes($name);
}
$conn = $sb->openConnection();
$dts = time();
$sql = "INSERT INTO `contact_queries` VALUES ('', '$name', '$my_db_string', 'n/a', 0, $dts)";
$result = mysql_query($sql, $conn) or die(mysql_error());
$content = '<div id="main_middle">';
$content .= '<span class="title">'.$sb->dt('Contact').'</span>
<p>'.$sb->dt('Thank you for your enquiry. We will contact you shortly.').'</p>
</div>';
// admin auto email.
$dts = date("d.m.y h:ia", time());
$admin_content = "New contact query at $dts";
$admin_content .= "\n\n--\n\n \r\n\r\n";
mail("email address", 'NOTIFICATION: new query', $admin_content, 'From: email address');
$FILE=fopen("./log/auto-contact.txt","a");
fwrite($FILE, $admin_content);
fclose($FILE);
echo pageHeader($sb);
echo pageContent($sb, $content);
echo pageFooter($sb);
}
?>
You probably already answered this for yourself, but if not you can set ReCaptcha to validate prior to submitting the form, much the same as HTML5 validation. It just won't let the user submit until the Captcha is correct. Now, I don't know if it will refresh the captcha if it is incorrect but most of the time I see people putting it into an iFrame so it doesn't refresh the page when refreshing the captcha.
As an alternative, you can use sessions to keep the data filled in.