Jump to content

Controlling where email came from PHP form


CrossY

Recommended Posts

Hello PHPFreaks,

 

 

I'm sorry about the vague topic title, but allow me to explain:

 

 

I got a PHP form with some fields, and it sends the input data to me, and a copy to the person that submits it.

 

Only the receiver of the email sees the email it came from as: [email protected], rather than just "example.com" or "[email protected]". Is there a way to control this, so people dont see the root host?

 

Coding:

// send email
$headers = "From: \"$naam\" <$email>\n";
$subject = "Contactformulier Kartalin";
$from    = "Kartalin.nl";
$message = " blabla their input etc. ";

mail ("$youremail", $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1");

 

If you need more of the code let me know, but as far as I can tell this seems to be the part where it can be changed (coming from a PHP-dummy ;) )

 

 

Thanks in advance!

 

Dave

I see that you're not actually using the $headers variable in your mail function.  so, $from = "Katralin.nl" isn't actually going to do anything in the headers... Check the http://php.net/mail function and the example it gives you to use the $headers is as follows:

 

<?php
$to      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

You may just need to make $from an actual e-mail address and your headers should be fine the way your example was.

 

That worked, thanks!

 

Another question though; I got this now:

 

$youremail = "[email protected], $email";

$subject = "Contactformulier Kartalin";
$from    = "Kartalin.nl <[email protected]>";
$message = "blabla"

mail ("$youremail", $subject, $message, "From: $from\nContent-Type: text/html; charset=iso-8859-1");

 

Though it sends the mail to me, and the person that submitted the form, but its rather ugly reading the mail (To: [email protected];[email protected]). Is there a way to get either of those into BCC?

 

Ive tried:

$youremail = "[email protected]";

$headers = "Bcc: $email" . "\r\n";
$subject = "Contactformulier Kartalin";
$from    = "Kartalin.nl <[email protected]>";
$message = "blabla"

mail ("$youremail", $subject, $message, $headers, "From: $from\nContent-Type: text/html; charset=iso-8859-1");

 

But then the form doesnt seem to send anything, or just 1 (to [email protected]), can't quite recall (tried alot of variables :P ).

 

Any help is appriciated!

 

Dave

why do you add a , between the headers? headers this should be only one string or not?

 

also like this:

 

$youremail = "[email protected]";

 

$headers = "Bcc: $email" . "\r\n";

$subject = "Contactformulier Kartalin";

$from    = "Kartalin.nl <[email protected]>";

$message = "blabla"

 

mail ("$youremail", $subject, $message, $headers." "."From: $from\nContent-Type: text/html; charset=iso-8859-1");

 

if this doesn't work then just use the mail() function twice. ;)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.