On shared web hosting server for security reasons it's not possible unauthenticated email sending through - i.e. - the simple mail() function.

To do it, you need to use through an authenticated external SMTP service, and so you need to use a specific library as, i.e., PHPMailer.

Various code examples to use PHPMailer: http://phpmailer.worxware.com/index.php?pg=examples

Basic example use:

require_once('../class.phpmailer.php');

$mail             = new PHPMailer(); // defaults to using php "mail()"

$body             = file_get_contents('contents.html');
$body             = eregi_replace("[\]",'',$body);

$mail->AddReplyTo("name@mydomain.com","First Last");

$mail->SetFrom('name@mydomain.com', 'First Last');

$mail->AddReplyTo("name@mydomain.com","First Last");

$address = "someone@yourdomain.com";
$mail->AddAddress($address, "John Smith");

$mail->Subject    = "PHPMailer Test Subject via mail(), basic";

$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test

$mail->MsgHTML($body);

$mail->AddAttachment("images/phpmailer.gif");      // attachment
$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
    

Found this article interesting?
Subscribe to DomainRegister´s newsletter!

You can unsubscribe at any time by simply clicking the link in the footer of our emails. For information about our privacy practices, please visit our website.

We use Mailchimp as our marketing platform. By clicking below to subscribe, you acknowledge that your information will be transferred to Mailchimp for processing. Learn more about Mailchimp s privacy practices here.

  • email, SMTP, php
  • 4 Users Found This Useful
Was this answer helpful?

Related Articles

 Fatal error: Uncaught exception 'Exception' with message 'DateTime::__construct(): It is not safe to rely on the system's timezone settings.

If you get following error message:Fatal error: Uncaught exception 'Exception' with message...

 How to set php.ini values using .htaccess

You can override global values of system variables re-setting them in .htaccessFor each system...

 PHP Parse error: syntax error, unexpected $end

This is a very common error, typically caused by a missing } used in PHP to denote content...

 allow_url_fopen

If enabled, allow_url_fopen allows PHP's file functions (such as file_get_contents() and the...

 Limiti funzione php mail()

per motivi di sicurezza sui nostri server di hosting shared Linux la funzione php mail() è...