0

I am trying to send an email using mail function in php. I have read the documentation and followed the examples but in vain. I don't know if I am doing anything wrong.

Can anyone please help me. I also followed other examples from the community without success.

And here also; Send email with PHP from html form on submit with the same script

Here is my code:

$name =array($_POST['name'],$_POST['email'],$_POST['phone'],$_POST['comments']);


    $to = "fasdjgasgd@yahoo.com";
    $subject = "Form submission";
    $message = "$name[0] wrote the following: <br/> $name[3]";

    $header = "FROM:".$name[1];
    mail($to, $subject, $message, $header);
Community
  • 1
  • 1
Alexander
  • 599
  • 2
  • 14
  • 25

2 Answers2

1

Your server does not have local mailserver.

There are few solutions:

  • Install local mail server if you have sufficient rights
  • Change your PHP settings to use other mail server (other open mailserver or auth-based ones like Gmail, Yahoo etc)
  • Use one of available mail libraries which supports IMAP / POP3 to handle mail sending.
  • SwiftMailer or Pear Mail are one of most commonly used.
0

PHP must be configured correctly in the php.ini file with the details of how your system sends email. Open php.ini file available in /etc/ directory and find the section headed [mail function].

Windows users should ensure that two directives are supplied. The first is called SMTP that defines your email server address. The second is called sendmail_from which defines your own email address.

The configuration for Windows should look something like this:

[mail function]
SMTP = localhost

sendmail_from = email@domain.com

This link will help you.

Jenz
  • 8,280
  • 7
  • 44
  • 77