How to remove "via" from email using mail() - php

I have read How to remove "via" and server name when sending mails with PHP?, however, it's not helping in this case.
I want to send an email to example#gmail.com, the email will be sent from example#hotmail.com, using PHP mail(), however when I do this, it says via example.prod.ex3.example.net. How would I remove that, bearing in mind I've tried the above solution? Here's my code.
<?php
$to = $_POST['to'];
$subject = $_POST['subject'];
$txt = $_POST['msg'];
$headers = "Return-Path: " . $_POST['from'] . "\r\n" . "From: " . $_POST['from'] . "\r\n" .
"CC: ".$_POST['from'];
mail($to,$subject,$txt,$headers);
header('Location: ..');
?>

Related

php mail reply subject

So I managed to use "reply-to" and set an email to be replied to, however I'm wondering if its possible to change the subject of the email after its replied? instead of Re: 'Original Subject'?
$header = "From: " . $from ."\r\nReply-to: " . $email . "\r\n";
maybe something like this?
P.S. this 2nd code doesn't work, its just to help me get my point across
$header = "From: " . $from ."\r\nReply-to: " . $email . "\r\nReply-subject: Company Support Message\r\n";

WordPress - prevents server from sending mails and wp_mail does't work?

Why WP prevent me from sending mail?
I created a file mail.php and tested the PHP mail():
$to = "somebody#example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster#example.com" . "\r\n" .
"CC: somebodyelse#example.com";
mail($to,$subject,$txt,$headers);
I uploaded it my server, in the root directory. I run it and I received emails with that.
But when I use
$message = trim($_POST['sender_message']);
$email = trim($_POST['sender_email']);
//php mailer variables
$to = get_option('admin_email');
$subject = "Someone sent a message from ". get_bloginfo('name') . ": " . $subject;
$headers = 'From: '. $email . "\r\n" .
'Reply-To: ' . $email . "\r\n";
// $sent = wp_mail($to, $subject, strip_tags($message), $headers);
$sent = mail($to, $subject, strip_tags($message), $headers);
var_dump($send); // bool true
if($sent) {
// do something
}
I get bool true in the var_dump check. But I never received any email from my server.
Any ideas? Have I missed something to configure in WP?
EDIT:
The server won't send any email from yahoo accounts! Why???
$to = "xxx#yahoo.co.uk"; // works!
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: bbb#yaho.co.uk" . "\r\n" . // won't work!
"CC: lau.tiamkok#gmail.com";
mail($to,$subject,$txt,$headers);

Mail is not sent from website's PHP Contact form

i m using a php form for sending the contact email from my website. the code is ok and working fine on one website but not working in second website. both website having difference server space and hosting. Not showing any error on page
code is below :
<?php
$name = $_REQUEST['rohini_name'] ;
$contact = $_REQUEST['rohini_contact'] ;
$email = $_REQUEST['rohini_email'] ;
$remark = $_REQUEST['rohini_message'] ;
$MailTxt = "Following are Details" . "\r\n" .
"============================" . "\r\n" .
"Name : " . $name . "\r\n" .
"Mobile : " . $contact . "\r\n" .
"Email : " . $email . "\r\n" .
"Remark : " . $remark . "\r\n";
$to = "ballu9868#gmail.com";
$subject = "Enquiry from rohiniseeds.com";
$headers = "From: www.rohiniseeds.com";
mail($to,$subject,$MailTxt,$headers);
?>
Please ask your hosting to make sure that mail funstion is supported.
Try adding an IF statement around the mail($to,$subject,$MailTxt,$headers) function as follows:
if(mail($to,$subject,$MailTxt,$headers)){
echo 'Success!';
} else {
echo 'Error!';
}
If it says Success then you know that it's being sent by the server, and the problem is when it's trying to hit the inbox. If it says error, then the problem related to the server.
Also, please use email#rohiniseeds.com in the from header, which is a valid email address, instead of the URL of the website.
Please try this
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);

PHP from field when sending mail()

I'm using PHP's mail() function and noticing that my mail is being shown from being sent by 'My Website' in my inbox, but when I click on the actual email it shows it being sent from mywebsite#sitename.localdomain.
Ideally I'd like to have it say being sent from 'My Website', but the reply email being 'no-reply#mywebsite.com', and not to have it say anything about #sitename.localdomain.
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website' . "\r\n" .
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
Is this an issue that I need to fix in Apache, or can I modify the headers within PHP?
Try this:
$to = trim(strtolower($_POST['to']));
$from = trim($_POST['from']);
$message = trim($_POST['message']);
$subject = $from . ' has shared a link with you';
$headers = 'From: My Website <no-reply#mywebsite.com>' . "\r\n" . // <- change your email here
'Reply-To:' . $to . "\r\n" .
'X-Mailer: PHP/';
mail($to, $subject, $message, $headers);
The Question and Answer #1 contains a serious security vulnerability -
$to = trim(strtolower($_POST['to']));
Will allow an attacker to use your website to email arbitrary spam and your site will be blocked from most search engines.
See
https://www.owasp.org/index.php/Top_10_2010-A1
My recommendation is to
Sanitize the to and from fields
Never ever ever copy the message in the post to the output unless carefully sanitized.

How do I include the submitters email in a PHP form?

I am using a simple HTML form for an event registration and I would like to send a PHP confirmation email to the registrant with the same information that is going to the administrator.
Here are the details:
$emailFromName = $_POST['name'];
$emailFrom = $_POST['email'];
$emailFromPhone = $_POST['phone'];
I would like to use the value from $emailFrom in the following email address to:
$emailTo = "name#domain.com", \"$emailFrom\";
edit: Added new configuration:
$emailHeaders = 'From: "Conference" <noreply#conference.org>' . 'CC: . $emailFrom .';
This obviously doesn't work, but you get the idea of what I am trying to.
Thanks!
You will need to add headers to the mail function...
for example:
$headers = 'From: Family History Conference <noreply#familyhistoryconference.org>' . "\r\n" .
'Reply-To: noreply#familyhistoryconference.org' . "\r\n" .
'CC: ' . $emailFrom . "\r\n";
and then
mail($to, $subject, $message, $headers);
References:
PHP Mail Function
You put "From: $name <$emailFrom>" in the additional parameters of the mail() function:
http://php.net/manual/en/function.mail.php
So, basically you want to CC a copy of the message to the user as well as the administrator?
It depends on which PHP library you're using to send it. If you're using the default PHP mail() function, you'll need to add additional headers:
// Additional headers
$headers .= 'Cc: ' . $emailFrom . "\r\n";
// Mail it
mail('admin#email.com', $subject, $message, $headers);

Categories