Can't get my 'sendmail.php' to work...

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
idrewuk
Forum Newbie
Posts: 1
Joined: Sun Dec 20, 2009 11:22 am

Can't get my 'sendmail.php' to work...

Post by idrewuk »

Hey everyone,

Sorry if I'm missing something obvious but I wondered if anybody could help me with my script.

I've got a new website, a want to have a contact form on there. I'm trying my script on a test basis but it just will not work, despite trying a few different things!

The sendmail.php code is as follows:

Code: Select all

<?php
  $email = $_REQUEST['email'] ;
  $message = $_REQUEST['message'] ;
 
  mail( "hello@explainyourself.co.uk", "Feedback Form Results",
    $message, "From: $email" );
  header( "Location: http://www.explainyourself.co.uk/thankyou.html" );
?>
and in my test webpage I've put the following:

Code: Select all

<html>
 
<head>
 
<title>Form test</title>
 
</head>
 
<body>
 
<form method="post" action="sendmail.php">
    Email: <input name="email" type="text" /><br />
    Message:<br />
    <textarea name="message"></textarea><br />
    <input type="submit" /> 
</form>
 
</body>
 
</html>
My host, Streamline, has a couple of [really bad] support pages on the topic and says:
In order for the script to work, you need to specify, via a fifth -f parameter, the domain from which the mail is being sent(-froot@yourdomain.co.uk). The PHP component uses SMTP (Simple Mail Transfer Protocol), and all StreamlineNet SMTP servers have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of your domains hosted by StreamlineNet.
Is that missing from my code? I'm confused and would love to have this working soon! :?
User avatar
daedalus__
DevNet Resident
Posts: 1925
Joined: Thu Feb 09, 2006 4:52 pm

Re: Can't get my 'sendmail.php' to work...

Post by daedalus__ »

i kind of want to punch you
http://us2.php.net/manual/en/function.mail.php: additional_parameters (optional) wrote:
The additional_parameters parameter can be used to pass additional flags as command line options to the program configured to be used when sending mail, as defined by the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option.

The user that the webserver runs as should be added as a trusted user to the sendmail configuration to prevent a 'X-Warning' header from being added to the message when the envelope sender (-f) is set using this method. For sendmail users, this file is /etc/mail/trusted-users.
rei27
Forum Commoner
Posts: 27
Joined: Thu Apr 30, 2009 4:17 am

Re: Can't get my 'sendmail.php' to work...

Post by rei27 »

i have the similar problem too. My mail() cant work.

Code: Select all

 
$to  = 'user1@OtherDomain.com' . ','; //Specify Multiple Recipients
        $to .= 'user2@OtherDomain.com';
        $subject = 'My PHP Email'; //Specify Email Subject
        $message = '
        <html>
            <head>
                <title></title>
            </head>
            <body>
                <p>Hello Exabytes,</p>
                <h2>My Testing HTML Email!</h2>
            </body>
        </html>
        '; //Specify Email Message
        $headers  = 'MIME-Version: 1.0' . "\r\n";
        $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
        //To send HTML mail, the Content-type header must be set
        $headers .= 'From: Exabytes <user@MyDomain.com>' . "\r\n"; //Specify Sender
        $headers .= 'Cc: user<user1@mail.com>' . "\r\n"; //Specify CC user
        $headers .= 'Bcc: user2<user2@mail.com>' . "\r\n"; //Specify Bcc User
        mail($to, $subject, $message, $headers); //sent it
 
indian98476
Forum Commoner
Posts: 78
Joined: Tue Dec 15, 2009 3:24 am

Re: Can't get my 'sendmail.php' to work...

Post by indian98476 »

try this code....it works for me....i connected with a sample database here named elvisstore....source is head first php and mysql.....use it according to ur needs with or without database....


<?php
$from='elmer@makemeelvis.com';
$subject=$_POST['sub'];
$text=$_POST['msg'];

//datbase connectivity
$user='root';
$pass='';
$dbname='elvisstore';
$server='localhost';
$dbc=mysqli_connect($server, $user, $pass, $dbname)
or die('Error connecting to MySQL server.');
$query="SELECT * FROM email_list";
$result=mysqli_query($dbc,$query) or die('Error connecting to database');
while($row=mysqli_fetch_array($result)){
$first_name=$row['first_name'];
$last_name=$row['last_name'];
$msg="Dear $first_name $last_name,\n $text";
$to=$row['email'];
mail($to,$subject,$msg,'From:'.$from);
}
mysqli_close($dbc);
?>
indian98476
Forum Commoner
Posts: 78
Joined: Tue Dec 15, 2009 3:24 am

Re: Can't get my 'sendmail.php' to work...

Post by indian98476 »

from what i see it should be from in single quotes rather in double quotes....like this 'from'.$email where $email is ur email taken from a form with text field from with the name email.....
Post Reply