Error in sending email from php Code - php

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.

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

Difficulty with sending mail in php [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 searched stack overflow as well as the Ubuntu forums. I am writing a website and I am hosting it myself using a LAMP server. I have a form that a user fills out and want it to send an email once the user clicks the submit button. So far I have tried sendmail, ssmtp, phpmailer, and installing mailutils and using postfix. The reason I believe that it's an issue with the mail program is because after testing I'm getting no errors from the code and I am unable to send mail from the commandline. I would prefer not to use phpmailer as I don't want to hardcode any passwords in the website in the event it gets compromised. I would appreciate any help someone could give me. I have included the mail script if you need config files let me know Thank you in advance.
<?php
session_start();
if(isset($_POST['submit'])){
$to = "jmaggsdf#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 = "Website Email";
$message = $first_name . " " . $last_name . " wrote the following:" . "\n\n" . $_POST['message'];
$type = 'plain'; // or HTML
$charset = 'utf-8';
$_SESSION['from'] = $_POST['email'];
$_SESSION['first_name'] = $_POST['first_name'];
$_SESSION['last_name'] = $_POST['last_name'];
$_SESSION['message'] = $_POST['message'];
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset=utf-8' . "\r\n";
$headers .= 'To: ' . $to . '<' . $to . '>' . "\r\n";
$headers .= 'From: ' . $from . '<' . $from . '>' . "\r\n";
if($first_name == NULL || $last_name == NULL || $from == NULL || $message == NULL){
header("Location: mailError.php");
die();
}
else{
//$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers);
header("Location: thanksPage.php");
//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.";
}
}
?>
It you are sending mail using local host then it will not send mail.
It requires live server.

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.

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

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

Using PHP Session variables to send email form

I am currently trying to use the same php session variables saved in the DB to fill in information for an email form. Unfortunately as far as i can see the code is correct but the email won't return errors or refuses to send.
var_dump ($_POST);
if
(isset($_POST['submit']));
$to = "brendonexus#gmail.com"; // this is your Email address
$from = $_SESSION['email']; // this is the sender's Email address
$fullname = $_SESSION['fullname'];
$subject = "ICE Live Streaming Event - Online questions";
$subject2 = "Copy of the questions you submitted.";
$message = $fullname . " asked the following:" . "\n\n" . $_POST['message'];
$message2 = "Thank you, your question has been received and will be put forward to the panel for consideration." . $first_name . "\n\n" . $_POST['message'];
$headers = "From:" . $from;
$headers2 = "From:" . $to;
mail($to,$subject,$message,$headers); // this is the message that is sent
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
echo "Mail Sent. Thank you " . $fullname . ", We have recieved your email.";
// You can also use header('Location: thank_you.php'); to redirect to another page.
Edit: I have managed to get it to send an email now but it seems that when i var_dump the session variables the only one that returns is the username. Whats confusing is that if the username works and all the other code is built the same then i do not understand why there is a compatibility issue.

Categories