0

I am creating a login page.For that, after the signup I need to send the mail to the user for verification.Therefore, I need to send mail.To send the mail, I tried with mail() function like this,

<?php
//sending email with the php mail()
mail('[email protected]', 'Subject Line Here', 'Body of Message Here', 'From: [email protected]');
?>

I have configured php.ini file also like below,

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25

; For Win32 only.
; http://php.net/sendmail-from
sendmail_from ="[email protected]"

I am using windows 64-bit.

And also I have tried with phpmailer. But,I didn't find any solution.Since, 2 day I am trying this.I am unable to do this one.

Can anybody help me to solve this?

Vidya
  • 63
  • 2
  • 10
  • What sort of error messages or unexpected behavior are you getting? (Also, as an etiquette pointer, [highlighting the urgency of your question](https://meta.stackoverflow.com/questions/326569/under-what-circumstances-may-i-add-urgent-or-other-similar-phrases-to-my-quest) is frowned upon) – Haem May 04 '18 at 10:59
  • Do you actually have an SMTP server running on your machine? Try running a command prompt (Start Menu > Run > cmd) and then `telnet localhost 25`. Does it connect? – lufc May 04 '18 at 11:02

1 Answers1

0

First of all if you are using the script on production server then ask your admin for the mail function is active or not . Some time on production server it's blocked by Site admin.

Second if you are using this script on localhost server means on your desktop then first you have to use the mail server start.

for example i am considering that you are using XAMMPP on windows then Your have to start the Mercury Mail Server From the XAMPP control panel. Mercury by default comes with postmaster and newuser two users.

Then You have to download Mozilla Thunderbird mail client and configure the newuser and postmaster user in mail client by following the Create New account > email using the newuser@localhost and manually configure the pop and smtp server and port . usually default ports.

you can use the sendmail_from ="newuser@localhost"

then check Mercury Mail server is running then test your script.

it will send the mail and you then check it in the Mozilla Thunderbird mail client.

Third : for setting the From: you have to use the header like below

$headers = "From: newuser < [email protected] >\n";

   <?php
     $send_to      = 'postmaster@localhost';
     $mail_subject = 'Subject of Your mail';
     $message_body = 'Body of your email like message form php script.';
     $headers = 'From: newuser@localhost' . "\r\n";
     mail($send_to, $mail_subject, $message_body, $headers);

  ?>

I hope this will solve the problem .

NOTE if you want to send email form localhost to gamil or any other mail site then you have to use the sendmail application or more tutorial Search the google Term like 'Send email via Gmail in PHP '

Er. Amit Joshi
  • 611
  • 5
  • 21