Mail to issue

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
nathanbrooks
Forum Newbie
Posts: 8
Joined: Tue Aug 18, 2009 10:59 am

Mail to issue

Post 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?
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Mail to issue

Post by pbs »

Can you please paste your code here
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Mail to issue

Post by jackpf »

Are you putting "From: your email address" in the headers?

And yeah, ditto. Post code.
nathanbrooks
Forum Newbie
Posts: 8
Joined: Tue Aug 18, 2009 10:59 am

Re: Mail to issue

Post 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>
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Mail to issue

Post 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.
nathanbrooks
Forum Newbie
Posts: 8
Joined: Tue Aug 18, 2009 10:59 am

Re: Mail to issue

Post by nathanbrooks »

Thank you very much.

Can you give me an example?
User avatar
jackpf
DevNet Resident
Posts: 2119
Joined: Sun Feb 15, 2009 7:22 pm
Location: Ipswich, UK

Re: Mail to issue

Post 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.
User avatar
arminium
Forum Newbie
Posts: 18
Joined: Wed Aug 12, 2009 10:02 pm
Location: Sunshine Coast, AUSTRALIA!!!!!!

Re: Mail to issue

Post 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);
?>
 
User avatar
arminium
Forum Newbie
Posts: 18
Joined: Wed Aug 12, 2009 10:02 pm
Location: Sunshine Coast, AUSTRALIA!!!!!!

Re: Mail to issue

Post 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
nathanbrooks
Forum Newbie
Posts: 8
Joined: Tue Aug 18, 2009 10:59 am

Re: Mail to issue

Post by nathanbrooks »

Thank you very very much :-)

Going to try it as soon as I can.
User avatar
lord_webby
Forum Commoner
Posts: 44
Joined: Wed Aug 19, 2009 9:01 am

Re: Mail to issue

Post by lord_webby »

Have you tried setting the sendmail_from in php.ini?
Post Reply