Hey guys

I'm new to this so here goes ......

I run a forum (phpBB3) and am now trying to get an contact us section on the home page.

I have no real PHP knowledge and am trying to get my head round how it all works.

Can I use the existing sendmail function in the contact us page and just construct the email I want to send using a form or will I have to write a new php page for send mail?

I have looked over loads of site and they all seem to give me this ....
"mail("$to", "$subject", "$email", "$message");"

Does this code simply bring up the users email program (i.e. Outlook) and load the mail into that? This is not the disired effect, I want it to send an email directly. I have a hsot that supports this so it should be possible.

I was going to use this kind of thing ...
<form name="emai" action="submit.php">

But couldn't find the original php code.

Can anyone point me in the right direction?

Dani AI

Generated

Short answer for : PHP's mail() sends the message directly from the webserver, it does not open the visitor's Outlook or other mail client. As already pointed out, it will work if the server's mail subsystem (sendmail/postfix on Linux, or SMTP configured on Windows/php.ini) is present and correctly configured. On many shared hosts this is ready; on a local PC you often need extra setup or an SMTP relay.

Practical steps to implement a safe contact form: post the form to a server script (use POST), validate and sanitize every field server-side, and never inject user input directly into mail headers. Reject input that contains newline characters to block header injection. Use a fixed From address on your domain and put the visitor email in a Reply-To header so SPF/DMARC are not violated. Log attempts and return clear success/failure feedback to the user.

Small, useful server-side check for header injection:

function has_header_injection($s) {
    return preg_match('/[\r\n]|%0A|%0D|\\n|\\r/i', $s);
}

For reliability and deliverability consider a library (PHPMailer/SwiftMailer) and send via authenticated SMTP rather than relying solely on the system mailer. SMTP with authentication keeps messages out of the spam folder more often and lets you use TLS. Add a CAPTCHA or honeypot and rate limits to block spam bots.

Troubleshooting checklist: test a tiny script on the host (not on local XAMPP), check spam folders, check server mail logs and phpinfo() for sendmail_path/SMTP settings, and ask host support if mail() returns true but nothing arrives. Before coding, also check whether phpBB3 or an extension already offers a contact form you can enable—reusing forum functionality is often simpler and safer than a custom script.

Recommended Answers

All 3 Replies

I have looked over loads of site and they all seem to give me this ....
"mail("$to", "$subject", "$email", "$message");"

Does this code simply bring up the users email program (i.e. Outlook) and load the mail into that?

No. It will send an e-mail directly. Try this simple code:

<? 
$header = "From: Myself <myself@billgates.com>\r\n";

mail("your@email.com", "testmail", "this is the contents", $header);
?>

I did not try it, but it should send you an email if you change "" to your own email adress.

Regards Niek

Mistake, please delete post.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.