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: example.com@webhost-mailserver.com, rather than just "example.com" or "info@example.com". 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

Link to comment
Share on other sites

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      = '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);
?>

Link to comment
Share on other sites

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 = "my.email@gmail.com, $email";

$subject = "Contactformulier Kartalin";
$from    = "Kartalin.nl <info@kartalin.nl>";
$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: my.email@gmail.com;submitter@example.com). Is there a way to get either of those into BCC?

 

Ive tried:

$youremail = "my.email@gmail.com";

$headers = "Bcc: $email" . "\r\n";
$subject = "Contactformulier Kartalin";
$from    = "Kartalin.nl <info@kartalin.nl>";
$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 my.email@gmail.com), can't quite recall (tried alot of variables :P ).

 

Any help is appriciated!

 

Dave

Link to comment
Share on other sites

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

 

also like this:

 

$youremail = "my.email@gmail.com";

 

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

$subject = "Contactformulier Kartalin";

$from    = "Kartalin.nl <info@kartalin.nl>";

$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. ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.