Question

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.

Was it helpful?

Solution

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.

OTHER TIPS

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top