PHP Mail Form Sending Random Emails Daily - php

I'm using a basic PHP mail form on a website & my client has mentioned to me that he is getting a random email every day or so in his inbox that is totally blank. I read about the issue and was thinking that the mail form is sending an email every time the page is loaded, is that correct? Or is this another issue?
PHP
<?php
$mail_to = "email1#gmail.com, email2#gmail.com"; // specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$web = $_POST['sender_web'];
$company = $_POST['sender_company'];
$addy = $_POST['sender_addy'];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'Web Prayer Request from ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";
$body_message .= 'Prayer Request: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
alert('Your prayer request has been submitted - thank you.');
window.location = 'prayer-request.php';
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('Message not sent. Please, notify the site administrator info#info.com');
window.location = 'prayer-request.php';
</script>
<?php
}
?>
Link to site: http://tinyurl.com/dy48jom
Your help is much appreciated!

You have to consider implementing captcha in your mail form so that automated scripts wont send mail from your domain .captcha also make sure that you make some of the fields as required (validate not only using js but also using server side php code).

Related

Inquiries : Sometime getting, sometimes not?

I have added a quick contact form in every page so clients can easily get in touch. However, three different things are happening as below:
sometimes getting inquiries from client. (Genuine I can say, we worked together)
sometimes getting blank message. with Unknown sender every alternate day.
Getting nothing. (Whenever I am trying to check whether all pages working or not. I am not getting email on first time. (Sometimes second, third, fourth time works).
My code is as follows:
PHP script I am using:
<?php
header('Content-type: application/json');
$status = array(
'type'=>'success',
'message'=>' some message '
);
//echo '<pre>';print_r($_POST);exit;
$name = #trim(stripslashes($_POST['name']));
$email_from = #trim($_POST['email']);
$websitelink = #trim(stripslashes($_POST['websitelink']));
$subject = 'iMarketingJunkies: Inquiry';
$message = #trim(stripslashes($_POST['message']));
// 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: <'.$email_from.'>' . "\r\n";
//$email_from = $email;
$email_to = 'myemail#email.com';//replace with your email
$body = 'Name: ' . $name . '<br><br>' . 'Email: ' . $email_from . '<br><br>' . 'URL: ' . $websitelink . '<br><br>' . 'Message: ' . $message;
$success = #mail($email_to, $subject, $body, $headers);
echo json_encode($status);
die;
?>
Can anybody please help me to get rid of this. I have tested all pages and I am sure we can't add submit button without any data. I am using Cloudfare.
Thank you

php - Can't send form with special characters character

I'm working on a contact form for my website and I'm trying to make the user submit their email and name through an HTML form. My form has a reCaptcha and here is the action file:
<?php
if(isset($_POST['submit']) && !empty($_POST['submit'])):
if(isset($_POST['g-recaptcha-response']) && !empty($_POST['g-recaptcha-response'])):
// Your site secret key
$secret = 'my_secret_key';
// Remote user address
$ip = $_SERVER["REMOTE_ADDR"];
// Get verify response data
$verifyResponse = file_get_contents('https://www.google.com/recaptcha/api/siteverify?secret=' . $secret . '&response=' . $_POST['g-recaptcha-response']);
$responseData = json_decode($verifyResponse);
if($responseData->success):
// Contact form submission code
$email = htmlentities(!empty($_POST['email'])?$_POST['email']:'');
$to = 'myemail#gmail.com';
$subject = 'A new email from ' . $email;
$htmlContent = '<p>' . $email . '</p>';
// 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: User <' . $email . '>' . "\r\n";
// Send email
#mail($to, $subject, $htmlContent, $headers);
#mail($email, $subject, $htmlContent, $headers);
endif;
endif;
endif;
?>
So if the user submits an # (at) in their email field, the email never gets sent. I suspect it could be because of the above code. Are there any kind of restrictions to which characters can be sent/accepted by mail? And if so why? I tried sending a message like this:
адгтф~`!#$%^&*()_-+=<,>.?/:;"'\|{}[]
And it never got to my email-box. Help would be really appreciated!

send auto response through php form

I'm trying to make it so if the e-mail sends successfully the $emailwill get a automatic response from the $mail_to preferably with HTML signature included.
CODE:
<?php
$mail_to = 'REMOVED#EMAILERE.com';
// specify your email here //
$name = $_POST['name'];
$email = $_POST['email'];
$reason = $_POST['reason'];
$message = $_POST['message'];
// Construct email subject
$subject = 'Enquiry Form Submission';
$body_message .= 'Stage Name: ' . $name . "\r\n";
$body_message .= 'E-mail Address: ' . $email . "\r\n";
$body_message .= 'Reason for Contacting: ' . $reason . "\r\n";
$body_message .= 'Message: ' . $message . "\r\n";
$body_message .= "IP Address: " . getUserIpAddr();
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $email . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){
?>
<script language="javascript" type="text/javascript">
window.location = 'http://www.sharpturnnetwork.com/forms/success';
</script>
<?php
}
?>
<?php
function getUserIpAddr()
{
if (!empty($_SERVER['HTTP_CLIENT_IP'])) //if from shared
{
return $_SERVER['HTTP_CLIENT_IP'];
}
else if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) //if from a proxy
{
return $_SERVER['HTTP_X_FORWARDED_FOR'];
}
else
{
return $_SERVER['REMOTE_ADDR'];
}
}
?>
If you're just trying to pass the user information to another PHP page (http://www.sharpturnnetwork.com/forms/success), form the URL using GET parameters (e.g., http://www.sharpturnnetwork.com/forms/success?ip=$ip). But honestly, I'm not really sure what you're asking.
Note: PHP mail() returns TRUE or FALSE, but it does NOT tell you whether the email was delivered successfully. This just is not possible in PHP.
From PHP documentation on mail():
Returns TRUE if the mail was successfully accepted for delivery, FALSE
otherwise.
It is important to note that just because the mail was accepted for
delivery, it does NOT mean the mail will actually reach the intended
destination.

How do I test a PHP mail function without mailing to the actual addresses

Would I test this php script by creating a simple form on an HTML page and then pointing the action attribute to the .php file? I have created the .PHP file, just don't know how to send it off.
<?php
$recipients = array('name#domain.com','name#domain.com',
'name#domain.com',
'name#domain.com',
); // i will be inserting the test email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$mail_to = $_POST[$recipients];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'College Newsletter: ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Message: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail(implode(',',$mail_to), $subject, $body_message, $headers);
?>
The server doesn't seem to like my implode method. (SEE ABOVE) I kept getting the error: Warning: implode() [function.implode]: Invalid arguments passed in so
I changed the PHP to this:
<?php
$to = array('name#domain.com','name#yahoo.com');
// specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['name'];
$mail_from = $_POST['mail'];
$message = $_POST['message'];
// Construct email subject
$subject = 'Breaking News: ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Message: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
mail($to, $name, $mail_from, $message, $headers);
?>
Now i get the error:
Warning: mail() expects parameter 1 to be string, array given in bulk_mailer_test.php on line 70
Anyone?
-Cheers,-qs
Your issue is with this code
<?php
$recipients = array('name#domain.com','name#domain.com',
'name#domain.com',
'name#domain.com',
); // i will be inserting the test email here
$mail_to = $_POST[$recipients];
$mail_sent = mail(implode(',',$mail_to)...
implode() wants an array. You're passing it a probably null value.
remove this $mail_to = $_POST[$recipients]; and just use mail(implode(',',$recipients)
$_POST is a superglobal to collect data from a submitted form. If you have listed your recipient addresses in an array.. then there is no need for one. If you want to collect multiple emails from the form, then do something like this...
$recipients = array($_POST['email_1'], $_POST['email_2'], $_POST['email_3'], $_POST['email_4'],
);

PHP Send-Mail form to multiple email addresses

I'm very new to PHP and am using a basic template 'send-mail' form on a contact page.
It's been requested that I send the email out to multiple email addresses when the "Submit" button is clicked. I've searched around & haven't quite found what I needed. What code do I need to add into the form below in order to send this out to multiple email addresses?
<?php
$mail_to = 'daniel30293#gmail.com'; // specify your email here
// Assigning data from the $_POST array to variables
$name = $_POST['sender_name'];
$mail_from = $_POST['sender_email'];
$phone = $_POST['sender_phone'];
$web = $_POST['sender_web'];
$company = $_POST['sender_company'];
$addy = $_POST['sender_addy'];
$message = $_POST['sender_message'];
// Construct email subject
$subject = 'Web Prayer Request from ' . $name;
// Construct email body
$body_message = 'From: ' . $name . "\r\n";
$body_message .= 'E-mail: ' . $mail_from . "\r\n";
$body_message .= 'Phone: ' . $phone . "\r\n";
$body_message .= 'Prayer Request: ' . $message;
// Construct email headers
$headers = 'From: ' . $name . "\r\n";
$headers .= 'Reply-To: ' . $mail_from . "\r\n";
$mail_sent = mail($mail_to, $subject, $body_message, $headers);
if ($mail_sent == true){ ?>
<script language="javascript" type="text/javascript">
alert('Your prayer request has been submitted - thank you.');
window.location = 'prayer-request.php';
</script>
<?php } else { ?>
<script language="javascript" type="text/javascript">
alert('Message not sent. Please, notify the site administrator admin#bondofperfection.com');
window.location = 'prayer-request.php';
</script>
<?php
}
?>
Your help is greatly appreciated.
You implode an array of recipients:
$recipients = array('jack#gmail.com', 'jill#gmail.com');
mail(implode(',', $recipients), $submit, $message, $headers);
See the PHP: Mail function reference - http://php.net/manual/en/function.mail.php
Receiver, or receivers of the mail.
The formatting of this string must comply with » RFC 2822. Some examples are:
user#example.com
user#example.com, anotheruser#example.com
User <user#example.com>
User <user#example.com>, Another User <anotheruser#example.com>
Just add multiple recipients comma seperated in your $mail_to variable like so:
$mail_to = 'nobody#example.com,anotheruser#example.com,yetanotheruser#example.com';
See
mail() function in PHP
Here is a simple example:
<?php
// Has the form been submitted?
// formSubmit: <input type="submit" name="formSubmit">
if (isset($_POST['formSubmit'])) {
// Set some variables
$required_fields = array('name', 'email');
$errors = array();
$success_message = "Congrats! Your message has been sent successfully!";
$sendmail_error_message = "Oops! Something has gone wrong, please try later.";
// Cool the form has been submitted! Let's loop through the required fields and check
// if they meet our condition(s)
foreach ($required_fields as $fieldName) {
// If the current field in the loop is NOT part of the form submission -OR-
// if the current field in the loop is empty, then...
if (!isset($_POST[$fieldName]) || empty($_POST[$fieldName])) {
// add a reference to the errors array, indicating that these conditions have failed
$errors[$fieldName] = "The {$fieldName} is required!";
}
}
// Proceed if there aren't any errors
if (empty($errors)) {
$name = htmlspecialchars(trim($_POST['name']), ENT_QUOTES, 'UTF-8' );
$email = htmlspecialchars(trim($_POST['email']), ENT_QUOTES, 'UTF-8' );
// Email Sender Settings
$to_emails = "anonymous1#example.com, anonymous2#example.com";
$subject = 'Web Prayer Request from ' . $name;
$message = "From: {$name}";
$message .= "Email: {$email}";
$headers = "From: {$name}\r\n";
$headers .= "Reply-To: {$email}\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
if (mail($to_emails, $subject, $message, $headers)) {
echo $success_message;
} else {
echo $sendmail_error_message;
}
} else {
foreach($errors as $invalid_field_msg) {
echo "<p>{$invalid_field_msg}</p>";
}
}
}

Categories