0

I have this script in php and i want to send.an email but it does not work for some reason. This script is running on a server on byethost.

I also know there are other similar posts but they didnt help me.

I do not know if the script contains errors or anything else.

   <?php
        $to = "somebody@example.com";
        $subject = "My subject";
        $txt = "Hello world!";
       $headers = "From:         
         webmaster@example.com" . "\r\n" .
         "CC: somebodyelse@example.com";

        mail($to,$subject,$txt,$headers);
    ?>

Thanks

patricksweeney
  • 3,939
  • 7
  • 41
  • 54
Nick
  • 2,818
  • 5
  • 42
  • 60
  • The first thing you want to do is confirm whether or not there are errors in the PHP log. You can also have it dynamically write out errors. If I was to make a blind guess, I would say that there's no mailserver tied to your host, so it can't send an email. – Aeolingamenfel Feb 16 '16 at 17:21
  • And how do i attach a mail server? Also can you propose a free web hosting (php,mysql) server to provide and an emailserver? – Nick Feb 16 '16 at 17:23
  • You have to set the mailserver information in the `php.ini`, or use a 3rd party library, like Pear Mail: http://stackoverflow.com/questions/712392/send-email-using-the-gmail-smtp-server-from-a-php-page. There are no free hosts that provide mail servers, its too costly and too easily abused for spam. – Aeolingamenfel Feb 16 '16 at 17:26
  • It is possible to use Gmail's front-facing SMTP server to send emails from your Gmail account, however. – Aeolingamenfel Feb 16 '16 at 17:26
  • `php.ini` config information: http://php.net/manual/en/mail.configuration.php – Aeolingamenfel Feb 16 '16 at 17:27
  • Where do i find this php.ini file. Iam not an admin i just have an account to a web hosting server. – Nick Feb 16 '16 at 17:38
  • It's different per host. You should create a blank page with this code on it: `` and it will tell you the location of your `php.ini` file. – Aeolingamenfel Feb 16 '16 at 17:39

2 Answers2

0

Well, PHP knows how to send an email, but it needs a mail server that actually does the sending.

Some free ones that I use are: https://sendgrid.com/

dbrree
  • 613
  • 7
  • 23
0

Use PHPMailer to send emails, email sending library for PHP.

rayees
  • 137
  • 3
  • 11