Search…

X3 Photo Gallery Support Forums

Search…
 
monsteri
Topic Author
Posts: 13
Joined: 05 Nov 2006, 16:18

Server doesn't support* php mail() function

24 Jun 2009, 14:41

Hey everyone, I've just setup a website for my mother @ www.carol-dines.com

Unfortunately, it turns out that my webhost (WebFaction) doesn't have a local instance of Sendmail running on their shared servers. Therein lies a problem, I think... Is there any way to make the standard ContactForm work without having the php mail() function enabled?

I ran a test using pain's "emailtest.php" thing, and it said OK. Also, when I send mail through the form, it says "Sent." I never receive any mail at the address I've provided in the config.

What am I doing wrong?

Thanks!
 
User avatar
mjau-mjau
X3 Wizard
Posts: 14452
Joined: 30 Sep 2006, 03:37

25 Jun 2009, 18:09

I am not sure it is possible to get the contact form top work if the server doesn ´t have sendmail function. Not sure why pain ´s emailtest.php would work either though ... Pain?

This would require some further investigation - Perhaps you can provide admin access in a private message to pain, referring to this post, and he will check it out?
 
monsteri
Topic Author
Posts: 13
Joined: 05 Nov 2006, 16:18

25 Jun 2009, 19:41

Will do, thanks!
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

26 Jun 2009, 10:38

I am afraid you need to contact your hosting support on that, we dont have control outside mail() function.

Are you receiving emails from email test or they are not leaving your host at all?
firedev.com
 
monsteri
Topic Author
Posts: 13
Joined: 05 Nov 2006, 16:18

26 Jun 2009, 12:35

Pain,

I uploaded the "emailtest.php" file to my web directory, and it gives me an "OK" when I open the page. So that seems to be fine.

Also, when I send a message via the contact form, the form responds with "Sent," which indicates that the mail is going through.

Nevertheless, I never receive an e-mail at any of the addresses I have supplied in the config. Is something going on at the back-end that I'm just not aware of?
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

27 Jun 2009, 07:45

As I said, we just mail() it to the addy you specified, if it says OK that means atleast function works, what happens after that is not under our control.

Looks like messages either not leaving your server at all, or getting blocked. If no address is receiving them - they probably never actually being sent.
Which can be resolved only by your admin, sorry.
firedev.com
 
monsteri
Topic Author
Posts: 13
Joined: 05 Nov 2006, 16:18

27 Jun 2009, 09:52

Sorry to keep nagging you all, but I think I've found a solution to this problem.

Another user with WebFaction wrote a script which basically allows you to replace the mail() function call with the smtp() function call without requiring any other changes.

The thread is here: http://forum.webfaction.com/viewtopic.p ... 3868#p3868

For quicker reference, the code is here:
Code
Code:

<?php
/***********************************************************************
This is a Pear::Mail implementation of the php mail() function to allow
scripts that use mail() to work on WebFaction with minimal edits. Place
the line:

require_once "pearmail.php";

at the head of any file that uses the mail() function. Because PHP does
not support function overriding, it is not possible to actually replace
mail(). Therefore, the package includes a function called smtp() which
is semantically close to mail(). All instances of the mail() function
have to be replaced with smtp (just edit mail to read smtp, leave the
parameter list alone).

Note that the $additional_parameters parameter is not supported by
smtp(). No placeholder is provided, so that the unavailability of
any behaviour depending on this parameter is flagged.

Place your SMTP server info at the top of the smtp() function in this
file. These parameters are kept here to avoid contaminating the namespace
of the including file.

Ensure that the From header is correctly formed if it is provided. The
SMTP server may refuse to send mail if it doesn't like the From header
or is no From header is provided. If smtp() is called without a From
header provided, a simple one will be added; ensure that the SMTP
server will accept the address given for $smtp_default_from.

Troubleshooting: A simple way to troubleshoot is to try uncommenting
line 80. The error message attribute of any error object returned by
the $smtp->send() method will be echoed.
************************************************************************/

require_once "Mail.php";

function smtp($to, $subject, $message, $additional_headers="") {
    
    # Declare SMTP Server Settings
    $smtp_server = "myserver.webfaction.com";
    $smtp_username = "username";
    $smtp_password = "password";
    $smtp_default_from = "nottotallybogus@example.com";
    
    # Cast inputs to strings
    $to = (string) $to;
    $subject = (string) $subject;
    $message = (string) $message;
    $additional_headers = (string) $additional_headers;
    
    # Re-construct the headers into an array as expected by Pear
    $raw_headers = explode("\n", $additional_headers);
    $headers = Array("To"=>$to, "Subject"=>$subject);
    foreach($raw_headers as $raw_header) {
        $header = explode(":",$raw_header,2);
        if (count($header) != 2) {
            continue;     # Here the behaviour may differ somewhat with mail()... 
                        # malformed headers will be discarded silently.
        }
        if (trim(strtolower($header[0])) == "to" || trim(strtolower($header[0])) == "subject") {
            continue;     # No overriding To and Subject
        }
        $headers[ucfirst(trim($header[0]))] = trim($header[1]); # Key will start uppercase
    }
    
    # Set a default From header if none was provided
    if (!array_key_exists("From", $headers)) {
        $headers["From"] = $smtp_default_from;
    }
    
    # Create the smtp object and send mail. Must return true on success,
    # false on failure.
    
    $smtp = Mail::factory("smtp", Array("host"=>$smtp_server, "auth"=>true,
                                        "username"=>$smtp_username, "password"=>$smtp_password));
    
    $result = $smtp->send($to, $headers, $message);
    
    if (PEAR::IsError($result)) {
        # echo $result->getMessage();
        return false;
    } else {
        return true;
    }
}
?>
Will this script even work? If so, could you guide me through replacing/editing the required files in the imagevue directory?

Thanks!
 
User avatar
mjau-mjau
X3 Wizard
Posts: 14452
Joined: 30 Sep 2006, 03:37

29 Jun 2009, 13:30

thanks for the tip!
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

29 Jun 2009, 13:36

Need to experiment with it, actually we had SMTP mail implementation in plans for future version. Will get back to this.
firedev.com
 
monsteri
Topic Author
Posts: 13
Joined: 05 Nov 2006, 16:18

29 Jun 2009, 15:59

Thank you guys for looking into this!

I'm anxious to see if this can be implemented.
 
zjk
Posts: 12
Joined: 27 Jul 2009, 09:58

03 Aug 2009, 16:05

if i were you i'd better use swiftmailer, i largely use it for my own projects and never had been in any trouble, or even get filtered as spam, even with html mail content ;)
 
User avatar
Nick
Imagevue Hitman
Posts: 2872
Joined: 02 May 2006, 09:13

04 Aug 2009, 12:04

Thanks for suggestion, looks nice and web2.0ish, but its like 700kb unpacked.. We'll see about that.
firedev.com
 
monsteri
Topic Author
Posts: 13
Joined: 05 Nov 2006, 16:18

04 Aug 2009, 14:02

Thanks for the suggestion zjk. I'm ready to try anything because I'm going crazy not being able to have this contact form fully functional.