Exchanging emails via gmail without revealing real email addresses - php

I have a php forum which has 50 users and i am wondering how i can exchange emails between members without revealing their real gmail email addresses.The forum works this way.A user 'A' opens a contact form and writes and email and sends it to user 'B'.The email sent is received by user 'B' but does not reveal the real email address of user 'A'.When user 'B' replies,user 'B's' email is not attached anywhere in the email.
Are their existing solutions for this kind of thing.

Have a look at the PHP mail() function.
$to = 'send_to#gmail.com';
$subject = 'Some message subject';
$message = 'Oi, what\'s up?';
$headers = "From: Bob < some_other_email#gmail.com>\r\n";
mail($to, $subject, $message, $headers);

Related

PHP 'mail()' Function Not Sending Email [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 using a basic script on a 1&1 hosted server:
$recipient = "email#domain.com";
$sender_name = $_POST['name'];
$sender_email = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0"."\r\n";
$headers .= "Content-type:text/html; charset=UTF-8"."\r\n";
$headers .= "From: {$sender_name} <{$sender_email}>"."\r\n";
$headers .= "Reply-to: {$sender_name} <{$sender_email}>"."\r\n";
mail($recipient, $subject, $message, $headers);
..but for some reason am not receiving any emails, nor any errors as per PHP mail() function not sending email instructs.
I thought this may be a server issue but 1&1 states that it is fully supported. I've also sent emails from this server/hosting before using just a recipient, subject and body and so I'm rather unsure as to why it is not working now!
UPDATE
Sending without headers, i.e.:
mail($recipient, $subject, $message);
..does work, so it would appear to be an issue with using the headers?
There may be many reasons, for example you should study what SPF is.
The $sender_email can't be any address, for example you can't put a gmail address and send emails claiming to be that sender, without any authentication, you aren't allowed to send email on behalf on that address, because I could for example send emails putting your address in the from, pretenting to be you when I'm not (I tried to use simple words)
You should use in the From something ending in #yourdomain.com, and set up SPF to allow your server's IP to send emails for that domain. OR otherwise send emails through SMTP (with PHPmailer, for example, it's very easy)
Errors in header does affect the mail delivery. if you send email with wrong headers, for example, let's say the email of the user is user#email.com and his name is "user user", and you send the email to user#email.com it might cause the email to go in spam or not accepted at all if it doesn't match on server.
Gmail, for one, has a name associated with every email id. if you put a wrong name with the email, there's a chance the email might not show up in inbox or sometimes even spams.
"But in the link I attached the example given uses a 'from' header set by a form input?"
if you want your users to be able to send email to you, best idea would be to use your own email address as the sender email. E.g. if your website is at website.com, configure an email like "contact#website.com" and configure your script to use this as From header, you can send it to your own email at the same domain(website.com) or any other email which you authorize. You can add the users's actual details in the mail. that'll ensure the successful delivery of the email always.

Is it possible to specify "Reply From" email address in form submission using PHP?

I have a form on my website which will send me an email using PHP. It will be sent to an email address from my hosting service, which I never check, so I set it up to forward emails sent to that address to my iCloud email address. This works great, since it preserves the "From" address so when I reply, it is sent to the person who filled out the form. The problem is, when I reply to the email sent from the form, the person who gets that reply will see it came from my iCloud account, and replies to that email will go directly to my iCloud account rather than to my hosting service email.
My question is, is there a way to specify in my PHP code what email should appear in the "From" field upon replying to the email (but of course, this is different from the "From" address in the first email sent to me (the person filling out the form)?
Essentially, I want it to work like this:
-Upon form submission, an email is sent to example#myhostingservice.com with the "From" address set to the email inputted in the form
-example#myhostingservice.com forwards the email to my iCloud account (but preserves the email address of person who filled out form in the "From" address)
-I reply to that email using my iCloud account, and the receiver sees it came from example#myhostingservice.com (not iCloud), and when they reply it goes to example#myhostingservice.com
Here is a snippet of my code to see what I'm working with:
$name = $_POST['name'];
$email_address = $_POST['email'];
$subject = $_POST['subject'];
$message = $_POST['message'];
if( empty($errors))
{
$to = $myemail;
$email_subject = "$subject";
$email_body = "Name: $name \n \n $message";
$headers = "From: $email_address";
mail($to,$email_subject,$email_body,$headers);
}
Thanks!
From docs (http://php.net/manual/en/function.mail.php):
$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);
Although I must warn you, doing such may mark your email as spam since the email address it is being sent from does not match the From header.
I don't think this is possible using PHP - the email client you use on your iCloud account sets the new "Reply-To". However, try to add the hosting email account to your iCloud email client -(Using POP3 or IMAP)- then you will be able to "Send as" your hosting account and you won't need to forward everything to iCloud.

Contact form in PHP: Allowing the user to send me an email

On my website I have a contact form, where the user can report bugs or submit feature requests. The form contains a subject and message.
I want the form to email me directly, either with PHPMailer or with PHP's built-in mail function.
The issue here is when generating the email, the sender has to be an address I own, not the actual user's email address. The reason for this is obvious, since we shouldn't be allowed to impersonate other people. However I want to be able to email my users back directly from my inbox, which I can't do since I can't use their address to email myself in the script.
What is the best way to construct the contact form then?
The only workaround I can think of is to insert the message + sender address into a database, and then read it manually from there....an epic hassle.
I would be grateful for any suggestions.
Set the Reply-To e-mail header, so you'll get something like this:
<?php
$headers = 'From: you#example.com' . "\r\n";
// Set the sender address as Reply-to below
$headers .= 'Reply-To: sender#example.com' . "\r\n";
mail('you#example.com', 'Subject here', 'The message goes here', $headers);
?>
This way you will be the sender, but when you hit the reply button in your mail client, it will default to reply to the address listed in the Reply-To header.
Why does the center have to be an address you own?
SMTP won't prohibit you from providing the email your user provides as the sender. As long as the SMTP server allows you to relay from it, it will take any value for sender and recipient.
Another option would be to make a sender email up (contact-form#yourdomain.com) and set the Reply-To field to your user's email address.
You can use the code below to receive an email from an address you own but when you reply it'll go to the user's email
<?php
$to = 'youremail#yourdomain.com';
$subject = 'the subject';
$message = 'message';
$headers = 'From: youremail#yourdomain.com' . "\r\n" .
'Reply-To: user#useremail.com' . "\r\n" .
mail($to, $subject, $message, $headers);
?>

Send e-mail with PHP to Facebook group mail address

1, I tried to send e-mail in PHP to my Facebook group email, but these updates, doesn't appear. If I send the e-mail from my yahoo mail, it posted instantly. What kind of information should I add to the mail header?
2, Is is possible to add images as attachments?
My current mail sender code is:
<?php
$to = "mygroup#groups.facebook.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "me#yahoo.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>
Does the email need to come from "me#yahoo.com"? Because Yahoo mail uses SPF, which Facebook can use to verify that your email didn't actually come from there, and discard your email as a spoofing attempt.
If the email needs to come from me#yahoo.com, you'll need to connect to Yahoo mail through SMTP, and pass your username and password through, and legitimately send your email from there.
As for image attachments, it's possible.
EDIT: As per the lovely DaveRandom's comment, the following PHP packages should make your job MUCH easier: PHPMailer or SwiftMailer

PHP email text to gmail account

Is there some way I can take text (retrieved from a form), and email it to my gmail account? I can also have the user enter their email address, and a subject. Or if not is there a better way to have users send me a message? Thanks.
Use mail function to send email to specific address:
$subject = $_REQUEST['subject'];
$message = $_REQUEST['message'];
mail("your#gmail.com", $subject, $message);
But please don't take $to parameter from form, otherwise your script will be used for spamming.
I recommend that you use PHP Mailer this program will take care of all of the message construction and works well with Gmail. There is also sample code included for Gmail.
Expanding on what Ivan wrote to add users email as sender:
$subject = $_POST['subject'];
$message = $_POST['message'];
$from = $_POST['from'];
// the sender email must be cleaned of mime header injection
$from = preg_replace_all("/[\r\n]+/", '', $from);
mail("your#gmail.com", $subject, $message, "from:$from\n");
This makes it easier to reply. However, you could just append their email address in the message body.

Categories