Page 1 of 1

Mail to issue

Posted: Mon Aug 24, 2009 6:26 am
by nathanbrooks
Hi there,

I used a php function 'mail' to send an email to the sender saying 'thanks for the enquiry' etc etc.

My problem is that once you receive the email, under the 'sent by' tab it doesnt show the senders address but instead shows a random address, such as 'www-data'.

What do I do to correct this issue?

Re: Mail to issue

Posted: Mon Aug 24, 2009 6:38 am
by pbs
Can you please paste your code here

Re: Mail to issue

Posted: Mon Aug 24, 2009 6:53 am
by jackpf
Are you putting "From: your email address" in the headers?

And yeah, ditto. Post code.

Re: Mail to issue

Posted: Mon Aug 24, 2009 6:58 am
by nathanbrooks
Sure here it is :

if (!empty ($_POST ['email']))
{
$sender=$_POST ['email'];
}

$info = array ($name, $surname, $mobile, $sender, $query);
$message="";
for ($i=0; $i < count($info); $i++)
{
$info [$i]=ucfirst ($info [$i]);
$message.=$info[$i]."\n";

}

mail("nathan@redzebramobile.co.za", $message, $sender);

HTML :
<tr>
<td width="100px">
Email :
</td>
<td >
<input name="email" type="text" class="searchBox">
</td>
</tr>

Re: Mail to issue

Posted: Mon Aug 24, 2009 6:59 am
by jackpf
Yeah, as I said, you're not putting a "From" header...so it'll send from the default email address in php.ini instead.

Re: Mail to issue

Posted: Mon Aug 24, 2009 7:29 am
by nathanbrooks
Thank you very much.

Can you give me an example?

Re: Mail to issue

Posted: Mon Aug 24, 2009 7:38 am
by jackpf
http://uk.php.net/manual/en/function.mail.php

Check out the examples and comments. You'll see they're putting "From: emailaddy" as the fourth arg.

Re: Mail to issue

Posted: Mon Aug 24, 2009 3:02 pm
by arminium

Code: Select all

<?php
 
 
$to = 'tommy@gizoo.com';
 
$subject = 'Example Subject';
 
// message
$message = '
<html>
<head>
  <title>Example</title>
</head>
<body>
  <p>Some text</p>
</body>
</html>
';
 
// sending HTML mail set the Content-type 
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
 
// Additional headers
$headers .= 'To: Wally <wally@one.com>, fred <fred@fred.com>' . "\r\n";
$headers .= 'From: Me <no-reply@tech.com>' . "\r\n";
$headers .= 'Cc: friends@tech.com' . "\r\n";
$headers .= 'Bcc: foes@tech.com' . "\r\n";
 
// Mail it
mail($to, $subject, $message, $headers);
?>
 

Re: Mail to issue

Posted: Mon Aug 24, 2009 3:05 pm
by arminium
or for your example just change

mail("nathan@redzebramobile.co.za", $message, $sender);


to


mail("nathan@redzebramobile.co.za", $message, "From: ".$sender);

should work ok

Re: Mail to issue

Posted: Tue Sep 01, 2009 2:39 am
by nathanbrooks
Thank you very very much :-)

Going to try it as soon as I can.

Re: Mail to issue

Posted: Tue Sep 01, 2009 3:30 am
by lord_webby
Have you tried setting the sendmail_from in php.ini?