1

I am using contact us form in my website and i want to send email through this. i got a sendemail.php script and integrated with my website. But when i filled the form and sent it, it shows email is sending and its forever. How can i make it to send email. Also do we need to host it in the website? I have it in my system and have to test the mail function before host the website. Here is my php script.

<?php
$name       = @trim(stripslashes($_POST['name'])); 
$from       = @trim(stripslashes($_POST['email'])); 
$subject    = @trim(stripslashes($_POST['subject'])); 
$message    = @trim(stripslashes($_POST['message'])); 
$to         = '<myemail@domain.com>';//replace with your email
$echo       =("Thank you for contacting us!");

$headers   = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From: {$name} <{$from}>";
$headers[] = "Reply-To: <{$from}>";
$headers[] = "Subject: {$subject}";
$headers[] = "X-Mailer: PHP/".phpversion();

mail($to, $subject, $message, $headers);

die;
FreedomPride
  • 1,098
  • 1
  • 7
  • 30
Arun
  • 35
  • 5

1 Answers1

0

The PHP mail() function will essentially try to send your email using whatever mail server you have pointed it to in your php.ini.

So, for mail() to work on your local machine you need to set up a local mail server.

Bananaapple
  • 2,984
  • 2
  • 25
  • 38
  • So do i need to create php.ini fine or it will automatically work after i host the web? means will the file available in web hosting server.? – Arun Aug 15 '17 at 14:55
  • Unless you are managing the server yourself you will likely not have access to the php.ini file on the server. However, your provider may have this configured for you so mail() could work on the server, but you may want to test it out first just to be safe. – Bananaapple Aug 15 '17 at 16:29
  • my web hosting site is different and the mail hosting is diffrent. How can i make the sendmail.php work. Do we need to configure the smtp in this file. – Arun Sep 08 '17 at 10:26