I have found something wrong in my website when I try to send an e-mail through the mail() function. The mail is not sent and I have this error message:
PHP Warning: mail() has been disabled for security reasons in
/home/natureex/public_html/mail/contact_me.php on line 24
This is my code:
<?php
// Check for empty fields
if(empty($_POST['name']) || empty($_POST['email']) || empty($_POST['phone']) || empty($_POST['message']) || !filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'geral#aaa.pt'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: info#aaa.pt\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
The line 24 is this one:
mail($to,$email_subject,$email_body,$headers);
I have contact my host and they said this:
Please be informed that, for security reasons, all email submissions
via PHPmailer must be authenticated. If you want to send e-mail via
PHP, you must have an e-mail account associated with it.
Related
I am using php mail() for sending email. with this function mail is being sent properly. But after sending mail page is not not loaded properly. Actually I want to land on same page after sending email.
following is the code that I have written
if (isset($_POST['submit'])) { // Check if form was submitted
if (empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['subject']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)) {
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$subject = strip_tags(htmlspecialchars($_POST['subject']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'myemail#gmail.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Subjet : $subject";
$email_body = "You have received a new message from your website contact form.\n\n" . "Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: myemail#gmail.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#gmail.com.
$headers .= "Reply-To: $email_address";
mail($to, $email_subject, $email_body, $headers);
header("Refresh:0");
return true;
// exit();
}
this is contact us page
after sending email this page is not loaded completely only header is loaded
It is probably because the mail sending fails.
You can see the error it is returning by adding the following on top of the PHP file:
ini_set('display_errors', 1);
Also, it is advisable to use PHPMailer, because the mail() function doesn't always work.
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['phone']) ||
empty($_POST['email']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
// Create the email and send the message
$to = 'info#bpmo-solutions.kz'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return readfile(polychor_file.pdf);
?>
I have a response and all work correct with status 200, so why did I cannot take my file back? I need to show pdf file after the form sent.
You need to change the Header:
header("Content-type: application/pdf");
header("Content-Disposition: inline; filename=filename.pdf");
#readfile('path\to\filename.pdf');
Take a look at the following example:
How to display PDF in PHP
I've adapted a simple contact form using php which works fine. However I now need to add an auto response email, so when the client has entered details into the form it not only sends me the details, but sends the client a html email response.
Can any of you kind clever people point me in the right direction on how to achieve this as I'm stuck. Below is the code I'm using; am I right in thinking I need to use another "if" statement to send auto reply?
Any help will be greatly appreciated
<?php
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
$to = 'andy#andydry.com';
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact
form.\n\n"."Here are the details:\n\nName: $name\n\nEmail:
$email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n";
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Send another email, but to the client, when the first email is sent successfully. That is assuming you're sending the client an email with different content than you're sending yourself when they use the contact form. Otherwise, use BCC.
Also, use a mail library such as Swiftmailer.
First off, a caveat: the php mail() function is prone to header-injection abuse, which can be used to force your mail server to spam emails on spammers behalf. Strictly filter incoming email addresses
As far as your question, you seem to be wanting to add a CC to your email of the customer's email address.
That is done through adding to the headers:
$headers .= "CC: ".$customer_email_address_sanitized_and_escaped."\r\n";
My site is here: vectormaid.com
I used a bootstrap template I liked with an existing contact form that only needed my email to work. I want to add a file upload to this form. I've already designed the button to my liking, and it functions well (you can select multiple files and they show as being selected within the form).
How do I add the php functionality to get the file upload portion to work? Everything else sends in an email just fine, so I know the form is working minus the file upload.
Here's my php for the form:
<?php
// Check for empty fields
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL))
{
echo "No arguments Provided!";
return false;
}
$name = strip_tags(htmlspecialchars($_POST['name']));
$email_address = strip_tags(htmlspecialchars($_POST['email']));
$phone = strip_tags(htmlspecialchars($_POST['phone']));
$message = strip_tags(htmlspecialchars($_POST['message']));
// Create the email and send the message
$to = 'artwork#vectormaid.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#vectormaid.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
I'm trying to get PHP to send an email to my email account but it's giving me this error:
http://gyazo.com/5e7870a814be520f2ba2dec32627c7e5
This is my code on contact_me.php
<?php
// Check for empty fields
if( empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['phone']) ||
empty($_POST['message']) ||
!filter_var($_POST['email'],FILTER_VALIDATE_EMAIL)
) {
echo "No arguments Provided!";
return false;
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
// Create the email and send the message
$to = 'yourname#yourdomain.com'; // Add your email address inbetween the '' replacing yourname#yourdomain.com - This is where the form will send a message to.
$email_subject = "Website Contact Form: $name";
$email_body = "You have received a new message from your website contact form.\n\n"."Here are the details:\n\nName: $name\n\nEmail: $email_address\n\nPhone: $phone\n\nMessage:\n$message";
$headers = "From: noreply#yourdomain.com\n"; // This is the email address the generated message will be from. We recommend using something like noreply#yourdomain.com.
$headers .= "Reply-To: $email_address";
mail($to,$email_subject,$email_body,$headers);
return true;
?>
Thanks guys!
If you are using ubuntu, you need to configure the sendmail or postfix to send emails.
Configure the postix by using the following link : http://crazybrainz.in/configauration-of-postfix-for-mail-sending-through-php-and-magento/
provide some more information to solve your problem.