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

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.

Related

How do I send an email to an email address with an custom message [duplicate]

This question already has answers here:
How can I send an email using PHP?
(20 answers)
Closed 5 years ago.
I wanted to send an email such as an confirmation email to an email address that the user has alredy specified in an input tag. Exampe:
I type in my email in an input tag and then I would recive an email at the address I entered in the input tag. Thanks, and If you know the answer could you possibly send me an code to paste in. (Im an php noob)
<?php
$recipient = $_POST['email']; //recipient
$email = "your#domain.com"; //senders e-mail adress
if((filter_var($email, FILTER_VALIDATE_EMAIL)) && ($robotest == "")) {
$Name = ($_POST['name']); //senders name
$mail_body = !!!----> WHAT DO I PUT HERE <----!!!!
$subject = "Porter Inquiry"; //subject
$header = "From: ". $Name . " <" . $email . ">\r\n"; //optional headerfields
mail($recipient, $subject, $mail_body, $header); //mail command :)
} else {
print "You've entered an invalid email address!";
}
?>

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

PHP mail() not sending a 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'm trying to learn a bit of basics of PHP, but as always I start from living examples like mailing. I'm not sure my tutorial was prepared good or I just made a couple of silly mistakes. There may be a problem with " ' because I haven't figured out which one should be where :) So, my mail is not sending an email, and definitely it's not going to spam so I believe I screw up ' and " part. Thanks for help!
$name = $_POST['nick'];
$visitor_email = $_POST['email'];
$visitor_tel = $_POST['tel'];
$message = $_POST['msg'];
$email_from = 'mail#mail.pl';
$email_subject = "Nowe zlecenie: ";
$email_body = "Nowe zlecenie od $name.\n".
"Email kontaktowy: $visitor_email".
"Telefon kontaktowy: $visitor_tel".
"Zlecenie: $message".
$to = 'mail#mail.pl';
$headers = "Od: $email_from \r\n";
mail($to,$email_subject,$email_body,$headers);
For debugging do like below:
if(mail($to,$email_subject,$email_body,$headers))
echo "mail sent";
else
echo "not send";

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