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('mahadev.3333@gmail.com', 'Subject Line Here', 'Body of Message Here', 'From: vidya.5555@gmail.com');
?>

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 ="vidya.merahkee@gmail.com"

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 < newuser@domain.com >\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
  • 1
    I am using wamp here. – Vidya May 04 '18 at 11:50
  • Not an Issue . if you want fast solution then simply download the XAMPP and stop the apache and mysql in XAMPP and let your wamp server run the Apache and Mysql . In XAMPP simply start the **Mercury Mail Server ** Try a test . I hope that will work. – Er. Amit Joshi May 04 '18 at 11:52
  • With send mail application also I have tried. But, still I am facing the same issue. I have referred the following video, https://www.youtube.com/watch?v=qqm64zHlFUg – Vidya May 04 '18 at 11:52
  • I have a query here,Is it can't be done using wamp? – Vidya May 04 '18 at 11:54
  • Yep you can do but it will take lots of Configuration and Like installing the seprate mail server and then configure and if you use the xampp then it simply download it then install it .... it will save time and error ... later on you can do your hard work. – Er. Amit Joshi May 04 '18 at 11:56
  • I have installed the separate mail server called phpmailer but still I am getting the same error..If I want to do this with wamp only what all the steps I need to follow – Vidya May 04 '18 at 12:01
  • PHPMailer is not the server its mail script written in php. Read the phpmailer description https://github.com/PHPMailer/PHPMailer – Er. Amit Joshi May 04 '18 at 12:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/170367/discussion-between-vidya-and-er-amit-joshi). – Vidya May 04 '18 at 12:07
  • I have as below it is working fine: - – Vidya May 10 '18 at 07:37
  • 1.In xampp/sendmail/sendmail.ini file, edit these lines [sendmail] smtp_server=smtp.gmail.com smtp_port=587 smtp_ssl=auto error_logfile=error.log auth_username=xxx.xxxx@gmail.com auth_password=xxx@123 – Vidya May 10 '18 at 07:39
  • 2.And in xampp/php/php.ini file edit these lines,[mail function] SMTP = smtp.gmail.com smtp_port = 587 sendmail_from = xxx.xxxx@gmail.com sendmail_path ="\"C:\xampp\sendmail\sendmail.exe\" -t" mail.add_x_header = On – Vidya May 10 '18 at 07:42
  • 3.And after editing restart xampp-control panel – Vidya May 10 '18 at 07:43
  • 1
    Thanks For Update – Er. Amit Joshi May 10 '18 at 07:43
  • 4. In php, $message="Check mail"; $headers="From:xxx.xxxx@gmail.com"; mail("user.@gmail.com","Testing",$message,$headers); echo "mail has sent"; – Vidya May 10 '18 at 07:44
  • don't forget to use ` "\r\n"` or line break. Read below post for good clearification https://stackoverflow.com/a/4415687/9128487 – Er. Amit Joshi May 10 '18 at 07:48
  • Thanks **Thumbs Up** Finally issue closed. :) – Er. Amit Joshi May 10 '18 at 07:50
  • Thank you Er.Amit Joshi for assisting me :) – Vidya May 10 '18 at 07:51