SitePoint Sponsor

User Tag List

Results 1 to 9 of 9
  1. #1
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    mail won't send; using mail() on PHP 5

    Hi All,

    I've just installed a small application on a remote server configured with PHP5. I'm using this mail class:

    PHP Code:
     <? 
    class minimail 
    // Private variable. 
    // Assigns email parameters. 
    var $data = array(); 
    // Constructs a minimail object. 
    function minimail($to$subject$message$from){ 
    // Creates message. 
    // Adds a "To" address. 
    $this->data['to'] = $to
    // Adds a "Subject" line. 
    $this->data['subject'] = $subject
    // Adds a "body" line. 
    $this->data['message'] = $message
    // Adds a "From" address. 
    $this->data['from'] = $from
    // Call send() function. 
    $this->send(); 

    // Sends mail using the mail program. 
    // Return true, otherwise call mail_error()! 
    function send(){ 
    $mail = @mail($this->data['to'], $this->data['subject'], $this->data['message'], 'From: '.$this->data['from']); 
    if(!
    $mail){ 
    $error 'Error sending message!'
    $this->mail_error($error); 

    return 
    true

    // Output the error message and terminate the script! 
    function mail_error($error){ 
    die(
    $error); 


    ?>
    And call it with: $mail = new minimail($to, $subject ,$message, $from);

    This all works fine on a server configured with PHP 4 but not this server. I asked the hosts about their configs. and this is what they said:


    We have checked the PHP.ini file on the server where the xxxxxxx website resides and this service has been configured to relay mail through our SMTP server "svwsmtp.xxxxxxx.net.uk"
    I receive no errors when I try to send a mail (using a form), I simply don't receive anything. Firstly, am I doing anything wrong? Is this class ok?Have I missed any configurations or something? Any help with this would be gratefully received. Thanks, Rob

  2. #2
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    what happens if you skip the class, and just use mail()?

  3. #3
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Well, I've just put together a very simple test like this:

    PHP Code:
       $to 'info@my_email_here.co.uk'// this is who receives the mail
       
          // these come from a user submitted form
           
    $name 'Rob';
           
    $telephone '0983838';
           
    $email 'rob@rob.net'// this is used as the 'from' 
           
    $enquiry "just a test";
          
          
    // contruct mail
           
    $headers $email;
           
    $subject 'Advice/General enquiry test: ';
           
    $message 'Message From: ' $name "\n\n" 'Telephone Number: ' .    $telephone "\n\n" 'E-mail address: ' $email "\n\n"  $enquiry;
           
      
    // send it
      
    mail $to$subject$message$headers); 

    But, same thing, no errors but no mail received either!! Any ideas?

  4. #4
    SitePoint Wizard silver trophy
    Join Date
    Mar 2006
    Posts
    6,132
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    check the junk mail/spam folder, it might be in there.

  5. #5
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Nope, it's not in there! Is there anything in particular I should be looking at when I prepare the mail() function, does the form fields need anything specific done to them i.e. remove form feeds etc. before I send? What couls stop it from being sent?

  6. #6
    SitePoint Zealot
    Join Date
    Jul 2002
    Location
    Wales
    Posts
    175
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just been doing some reading and I'm thinking, will I somehow need to connect to the smtp server svwsmtp.xxxxxxx.net.uk i.e. authenticate, before I send? And what about the port (25) do I need to somehow hake this into consideration? Excuse my ignorance!

    Rob

  7. #7
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    1
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If it is in a web host, check with the company, maybe they have some restrictions to sending mail

  8. #8
    Wadge! F4nat1c's Avatar
    Join Date
    Oct 2005
    Location
    South Wales, UK
    Posts
    1,134
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    PHP Code:
    ini_set("SMTP""svwsmtp.xxxxxxx.net.uk"); 
    Add that before your mail code.
    OMFG SitePoint ROXORZ TEH BIG ONE111!
    Wish you were invisible?

  9. #9
    SitePoint Enthusiast
    Join Date
    Jul 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hva you checked that mail() returns true? Try:

    PHP Code:
    if( mail $to$subject$message$headers) ){
      echo 
    'email sent';
    }
    else{
      echo 
    'email not sent';



Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •