my code doesn't work (php) [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
my code save info in database but doesn't send the message to email and the alert message not work.
can you help me , please ?
`
if(isset($_POST['send'])){
$to = "nada_26_#hotmail.com"; // this is your Email address
$subject = "Form contact";
$subject2 = "Copy of your form submission";
$name = $_POST['name'];
$from = $_POST['email'];
$subject3 = $_POST['subject'];
$company = $_POST['company'];
$content = $_POST['message'];
$message = "Name: ".$name ." Subject: " . $subject3 . " Company: " . $company ."\n\n".$content;
$message2 = "Here is a copy of your message " . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers); //send the message to the admin
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
$sql ="INSERT INTO threadnn_arab.contactus VALUES('$name','$from','$subject3','$company','$message','')";
$result=mysql_query($sql);
echo "<script> alert('Mail Sent, Thank you, we will contact you shortly.'); </script>";
header('Location: index.php?#contact');
}
?> `

i think it on your email provider, smtp may be.or you can using PHPMailer look like in this question Send email from Hotmail using php

Related

I have created a contactform using mailfunction. But all the mails are going to spam.My code is given below

I have created a contactform using mailfunction. But all the mails are going to spam.My code is given below
<?php
// MAIL SEND PHP
if(isset($_POST['submit'])){
$to = "abc#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
$email = $_POST['mail'];
$name = $_POST['name'];
$subject = "Form submission";
$subject2 = "Copy of your form submission";
$message = $email . " " . $name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
}
// END MAIL SEND PHP
?>
as i previously facing this issue , you can use phpmailer for this problem. with smtp details, hope fully that will working correctly.
checkout this link- click here

Error in sending email from php Code

The above error is occurring while we sent email from php code my code is
<?php
//if(isset($_POST['submit'])){
$to = "abc#gmail.com"; // this is your Email address
$from = $_POST['email']; // this is the sender's Email address
// $first_name = $_POST['first_name'];
//$last_name = $_POST['last_name'];
$subject = $_POST['subject'];
$subject2 = "Copy of your form submission";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
// You cannot use header and echo together. It's one or the other.
//}
?>
it is refered from this stackoverflow link
the error is as Follows:
Warning: mail(): SMTP server response: 550 No such
user here in D:\InetPub\vhosts\aaa.com\httpdocs\sendform.php on line
15
Warning: mail(): SMTP server response: 550 No such
user here in D:\InetPub\vhosts\aaa.com\httpdocs\sendform.php on line
16
The error is returned by Gmail SMTP server and tells you that the e-mail address your script sends mail to doesn't exist on Gmail servers.
It's not a PHP error.

PHP - send a form to e-mail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
I have a problem with sending the form to my e-mail.
Currently, when i send the form i get message from "emailtest#test.com" with $message2 but i don't get $message from 'inputEmail' to my e-mail "emailtest#test.com".
I would add that I am not PHP programmer and this is my first script in this language.
I would be very grateful for your help
<?php
$to = 'emailtest#test.com'; // this is your Email address
$from = $_POST['inputEmail']; // this is the sender's Email address
$first_name = $_POST['inputName'];
$inputCompany = $_POST['inputCompany'];
$inputPosition = $_POST['inputPosition'];
$inputProjects = $_POST['inputProjects'];
$inputOfficeProjects = $_POST['inputOfficeProjects'];
$inputPresentation = $_POST['inputPresentation'];
$inputMessage = $_POST['inputMessage'];
$number = $_POST['number'];
$subject = "Test";
$subject2 = "Test1";
$message = $first_name . " example " . $inputPosition . " wrote the following:" . "\n\n" . $_POST['message'];
$message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
// echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
header('Location: dziekujemy.html');
?>
Since your code works in a local environment, with mailtodisk, I suspect a "problem" with the mail server. You are setting the From: Header of the first email send attempt to the email address of the person that filled out the form. Most mail servers might reject that because it is not a valid address that you own. I am not an expert to this so someone might have a better, more detailed explanation.
Remove the headers from the first email or set the From: Header to a address which can actually sent over that mailserver. If this works you can use a Reply-to header which enables most clients to directly answer to the set email address.
Example below:
...
$headers = 'From: ' . $to . "\r\n" .
'Reply-To: '.$from;
...
I might suggest - even it it looks complicated at first - to use PHPMailer. It makes sending emails with PHP much easier.

php email function not working with .org email [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 6 years ago.
So I am trying to send an email to notify the office admin of when an email has been submitted through a form. Everything worked with no problems when I used an email ending in ".com" However, when I tried using an email ending in ".org"
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email_address = $_POST['email_address'];
$message = $_POST['message'];
if(isset($_POST['submit'])){
$to = "officeadmin#example.org"; // Office Admin Email
$from = $email_address; // User's Email
$subject = "Form Submission";
$content_admin = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $message;
$content_user = "Thanks again for contacting us. A dedicated staff member will contact you as soon as possible. Your message was: \n\n" . $message;
$headers_admin = "From:" . $from;
$headers_user = "From: Example Office";
mail($to,$subject,$content_admin,$headers_admin); //Notification email for admin
mail($from,'Thanks for contacting us',$content_user, $headers_user); //Copy of email sent to user
header('Location: contact_form_success.html'); //Redirect here after submit is clicked
}
Basic mail() function is not well configured so sometimes problem may arise, so you
Try PHPMailer, it is well configured php mail class for sending mail.

mail sending in php on live server still not sent mail [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
Mail sending in php on live server has still not sent mail.
if(isset($_POST['submit'])) {
/*$to = "rahulravalinfo#gmail.com";
$subject = "".$_POST['name']." New Inquiry About
".$_POST['subject'].""; $message = "Contact No.
".$_POST['contact']." Message ".$_POST['message']." Email
".$_POST['message'].""; $header = "From:rahulravalinfo#gmail.com
\r\n"; $retval = mail ($to,$subject,$message,$header); */
$to = "rahulravalinfo#gmail.com"; // this is your Email address
$from = $_POST['name']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "New Inquiry from". $_POST['name'];
$message = "Contact ".$_POST['contact'] . $first_name . " wrote the following:" . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to; $retval = mail($to,$subject,$message,$headers);
if( $retval == true ) {
$i=1; } else {
$i=2; } }
Please ask your server hosting company for the php mail is enable for your selected plan or not.
You can check it using php
if ( function_exists( 'mail' ) )
{
echo 'mail() is available';
}
else
{
echo 'mail() has been disabled';
}

Categories