954,202 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Generate Email script

How can i make this script work?
It is meant to send an email to a person with a confirmation code, but it is not working. whats wrong with it?

<?php

 function send_mail($fromname,$frommail,$to,$subject,$body,$priority)
  {
    $fullmail = "\"$fromname\"<$frommail>";
    $headers  = "From: $fullmail\n";
    $headers .= "X-Sender: $fullmail\n";
    $headers .= "X-Mailer: PHP\n";
    $headers .= "X-Priority: $priority\n";
    $headers .= "Return-path: $fullmail\n";

    mail($to,$subject,$body,$headers);
  }

 function send_html_mail($fromname,$frommail,$to,$subject,$body,$priority)
  {
    $fullmail = "\"$fromname\"<$frommail>";
    $headers  = 'MIME-Version: 1.0' . "\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\n";
    $headers .= "From: $fullmail\n";
    $headers .= "X-Sender: $fullmail\n";
    $headers .= "X-Mailer: PHP\n";
    $headers .= "X-Priority: $priority\n";
    $headers .= "Return-path: $fullmail\n";

    mail($to,$subject,$body,$headers);
  }

?>
tomf
Newbie Poster
9 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

What kind of error are you getting? The odds are the problem lies somewhere else in the code.

stymiee
He's No Good To Me Dead
Moderator
3,360 posts since May 2006
Reputation Points: 161
Solved Threads: 38
 

We can't debug unless we know what the problem is :) The format for the output should be headers, then a single blank line, and then the message.

cscgal
The Queen of DaniWeb
Administrator
19,421 posts since Feb 2002
Reputation Points: 1,474
Solved Threads: 229
 

Well, its just not sending the email at all!

tomf
Newbie Poster
9 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 

You'll need to echo out some variables in your script to make sure you have the right information there and to make sure you are getting there at all.

stymiee
He's No Good To Me Dead
Moderator
3,360 posts since May 2006
Reputation Points: 161
Solved Threads: 38
 

What OS is your server on?

Windows requires an SMTP server.

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

Its clustered linux servers i think

tomf
Newbie Poster
9 posts since Apr 2007
Reputation Points: 10
Solved Threads: 0
 
Its clustered linux servers i think

Check first with your hosting company support and see if they have mail() set up properly. If they either you have a problem with your code or your mail may be blocked or added to spam.

You'll need to place some debugging into your code.

for starters:

[PHP]if (!mail(....)) {
echo 'Mail is not working... ';
}[/PHP]

mail() will return Boolean true or false if working or not respectively.

Set your error reporting to max:

[PHP]error_reporting(E_ALL);

ini_set('display_errors', 'true'); // not sure bout this one, I think thats the correct config option[/PHP]

Just try a simple mail() first.. don't use the abstraction function "send_mail".. just to test if its working.

Check if your hosting company's mail servers are not blacklisted.
Send emails to a few different addresses to make sure its not specific to an email address...

digital-ether
Nearly a Posting Virtuoso
Moderator
1,293 posts since Sep 2005
Reputation Points: 461
Solved Threads: 101
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You