0

I am trying to send this user information inserted by a user in an HTML form to my email address using php:

  $to = "my_email@yahoo.com"; 
  $subject = "Delete Listing"; 
  $email = $_REQUEST['Email'] ; 
  $message = $_REQUEST['Filename'] && $_REQUEST['reason']; 
  $headers = "From: $email This File needs to be removed in 48 hrs.Please review it and act accordingly."; 
  $sent = mail($to, $subject, $message, $headers) ; 
   if($sent) 
     {print "Your mail was sent successfully"; }
   else 
      {print "We encountered an error sending your mail"; }

But I think I am not sure about using two $_REQUEST at the $message...that's why am getting the error in sending the email. (The else part gets executed "We encountered an error sending your mail")

5 Answers5

0

If you use $message = $_REQUEST['Filename'] && $_REQUEST['reason']; this makes a condition and if you want to concatenate them, use .

$message = $_REQUEST['Filename'] . $_REQUEST['reason']; .

MTM
  • 919
  • 10
  • 22
  • Yupe I tried that too but still getting error...So, just to make sure if it is working I tried using with one $_request only...but still getting error...i guess its something else...Do I have to set some kind of email client or something ??? –  Jul 13 '14 at 07:16
  • can you update the question with the error? – MTM Jul 13 '14 at 07:19
  • The else part gets executed.... –  Jul 13 '14 at 07:23
  • try with static values for all your variables, just to check if there is no problem with your email gateway. Except $to should has a valid email address – MTM Jul 13 '14 at 07:26
0

(I think) the problem is:

If you don't have an originating email to register from, no email server will accept the message. One of the features of email spamming protection. Try not to use the mail() function unless you know clearly what you are doing.

  • I am sorry but I don't understand...by originating email. –  Jul 13 '14 at 07:10
  • When I say "originating email", I am trying to say that the email *Originates from your server, but who on your server, like a pseudo-user called "mailman", or "noreply"?* – php_coder_3809625 Jul 13 '14 at 07:13
0
 $message = $_REQUEST['Filename'] && $_REQUEST['reason']; 

Here you just get TRUE or FALSE. Try this

 $message = $_REQUEST['Filename'] . ' ' . $_REQUEST['reason'];  
markoCarbo
  • 56
  • 3
0

Try :

$message = "I'm an example.";
mail('my_email@yahoo.com', 'Delete Listing', $message);

If you receive the message, you can to use full code.

Try with FastMailBuilder class, easy to use it :

(new FastMailBuilder)
    ->to('my_email@yahoo.com')
    ->from('New Site', 'no-reply@yourdomain.com')
    ->subject('Delete Listing')
    ->text(
        "This File needs to be removed in 48 hrs. Please review it and act accordingly."
    )->html(
        "This File needs to be removed in 48 hrs. <strong>Please review it</strong> and act accordingly."
    )->send();

Local Mail Server for Sending Mail

A typical configuration on you php.ini might look like:

[mail function]
SMTP = smtp.isp.net
sendmail_from = me@isp.net

Configure PHP to Use a Remote SMTP Server for Sending Mail

How To Use Gmail or Yahoo with PHP mail() Function

Learn more here : How To Use Gmail or Yahoo with PHP mail() Function

user2226755
  • 12,494
  • 5
  • 50
  • 73
  • Nope still not getting the mail...OK I am using my yahoo mail: shirishkadam35@yahoo.com so is it ok?? –  Jul 13 '14 at 07:21
  • What you use to hosting your website ? To local mail see : http://email.about.com/od/emailprogrammingtips/qt/Configure_PHP_to_Use_a_Local_Mail_Server_for_Sending_Mail.htm – user2226755 Jul 13 '14 at 07:28
  • Localhost: on my PC for practice purposes... –  Jul 13 '14 at 07:32
  • You need to update your php.ini to use mail function. (For the SMTP server see on google "[ISP's SMTP Mail Server](http://bit.ly/1mKRpgB)" to find your SMTP server of your Internet service provider). – user2226755 Jul 13 '14 at 07:37
  • Hey thanx It was the SMTP problem If some one needs here is the like to set it up https://www.digitalocean.com/community/tutorials/how-to-use-gmail-or-yahoo-with-php-mail-function –  Jul 13 '14 at 08:00
0

Make sure you have configured your php.ini file of your local server. If email settings are not configured well then this code will be useless. So first checkout your php.ini file.

Vidhyut Pandya
  • 1,605
  • 1
  • 14
  • 27