3

Hi I need to send email using php. But when I am trying to send a simple email,it is not being sent.What could be the reason? Should I include any header or any permissions?Please help me. Here is my code.

<?php
$to='jyothi.jish@gmail.com';
$message='hai';
mail($to, 'My Subject', $message);
?>

Even this small message is not being sent.Can anyone guess what could be the reason?

user2934937
  • 35
  • 1
  • 5
  • 11

3 Answers3

0

Well the issue in you need to define mail sending parameters in your server. Such as the mail host, ports etc. The best would be to use http://phpmailer.worxware.com/. You can use the third party such as gmail to send mails for you through your localhost development environment.

You can use

$mail = new PHPMailer();
$mail->CharSet = 'UTF-8';

$mail->Host       = "mail.example.com"; // SMTP server example
$mail->SMTPDebug  = 0;                     // enables SMTP debug information (for testing)
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Port       = 25;                    // set the SMTP port for the GMAIL server
$mail->Username   = "username"; // SMTP account username example
$mail->Password   = "password";        // SMTP account password example

to define the connection parameters.

Ela Buwa
  • 1,652
  • 3
  • 22
  • 43
-1

This is how you can send emails from XAMPP or WAMP (localhost) in PHP in Windows.

a) Open the "php.ini". For XAMPP,it is located in C:\XAMPP\php\php.ini. Find out if you are using WAMPP server.
Note : Make a backup of php.ini file

b) Search [mail function] in the php.ini file.

You can find 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 = postmaster@localhost

Change the localhost to the smtp server name of your ISP. No need to change the smtp_port. Leave it as 25.
Change sendmail_from from postmaster@localhost to your domain email address which will be used as from address..

So , it will become like this.
[mail function]
; For Win32 only.
SMTP = smtp.planetghost.com
smtp_port = 25
; For Win32 only.
sendmail_from = info@planetghost.com

c) Restart the XAMPP or WAMP(apache server) so that changes will start working.

d) Now try to send the mail using the mail() function .
Chirag Nagpal
  • 729
  • 10
  • 25
-1
Gmail SMTP server settings for sending mail through Gmail from any email program:

Gmail SMTP server address: smtp.gmail.com
Gmail SMTP user name: Your full Gmail address (e.g. example@gmail.com)
Gmail SMTP password: Your Gmail password
Gmail SMTP port: 465
Gmail SMTP TLS/SSL required: yes 

This will provide you facility to send mail using smtp via gmail(But i can not test it yet so you can try it and check it if its work for you).

Chirag Nagpal
  • 729
  • 10
  • 25