1

I'm working on a contact form for my church website.

The church has an email already registered (it's POP3) and the hosting company says their mail server is mymail.brinkster.com .

With all that information, how can you send the form using mail()? The server won't show PHP errors. The current code looks like this:

    $headers = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: *ChurchsEmail*' . "\r\n";

if(mail("*MyEmailHere*", "Setting Up PHP Email", "This would be the body of the email.", $headers))
{
        echo "The email was successfully sent.";
} else {
        echo "The email was NOT sent.";
}

All I get back is "The email was NOT sent."

So does anyone have any experience setting up an email form like this? My thanks to anyone who can help me out and any efficient ways of doing this, let me know!

3
  • Any chance you can check your mail servers logs for any errors? Maybe somewhere in /var/log/mail.(log|warn|error) - if on a linux server.
    – Abs
    Apr 8, 2010 at 23:03
  • I've just looked at what I have for my site. The only difference, aside from a valid to email address, is where you have $headers I have just "From: [email protected]". Apr 8, 2010 at 23:05
  • There is no /var/ folder when I browse my site, only a public_html and an includes, and it's a linux server. The headers I took from an about.com article on the subject. Just set them up incase that's what was wrong to begin with. Once I can get an email sent out I'll find out what I really need to have in the headers.
    – NessDan
    Apr 8, 2010 at 23:13

3 Answers 3

1

To use the PHP mail() function directly, your server has to be properly set up with a mail server.

If you want to send mail over SMTP through an external account/server I suggest you use a library found here: http://phpmailer.worxware.com/
You could also use their PHPMailer-FE which will even convert your contact form into an email for you.

2
  • I saw that and decided I'd rather just stick with the basic mail() function. For our website we have a very basic hosting plan, do you think they would restrict access to setting up a mail on the server?
    – NessDan
    Apr 8, 2010 at 23:17
  • 1
    Actually if it's a decent hosting company, they should see that the mail function works as it should. However, if you will send email from a mail address not associated with the mail server, it is going to get flagged as spam very easily. On a shared hosting plan, you will not have the option of setting up your own mail server. You should probably ask your hosting company for support.
    – mgw
    Apr 8, 2010 at 23:26
0

You probably need to configure it. The cli/apache user need to have access to sendmail.

2
  • I don't have access to the PHP.ini file. Is it common for someone to have access to it?
    – NessDan
    Apr 8, 2010 at 23:15
  • @NessDan - Yes, it should be.
    – Abs
    Apr 8, 2010 at 23:17
0

I was searching through their support database and found out how to get email working. It told me to include a server-file called "class.phpmailer.php"

Article for Brinkster users.

Thanks everyone for the help!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.