Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sending a mail via php script in ubuntu

Tags:

linux

php

email

I am trying to send a mail to my gmail id via php script in ubuntu but unable to send it. My code

<html>
<head><title>Send mail</title></head>
<body >


<?php
$name=$email=$query="";
if($_SERVER["REQUEST_METHOD"]=="POST"){
 $name = test_input($_POST["name"]);
   $email = test_input($_POST["email"]);
   $query = test_input($_POST["query"]);
 if(mail("[email protected]","Subject",$query,"From: $email\n")){
 echo "email send";
}else{
echo "not send";
}
}
function test_input($data) {
   $data = trim($data);
   $data = stripslashes($data);
   $data = htmlspecialchars($data);
   return $data;
}
?>

<form method="post" action="<?php echo ($_SERVER["PHP_SELF"]);?>">
Name:<input type="text" name="name" required>


  Email id:<input type="email" name="email" required>
    Query:<textarea name="query" row="5" cols="40" required></textarea>

   <input type="submit" value="Submit">

    </form>

    </body>
</html>

I have configured my php.ini

[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 = 

; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
; http://php.net/sendmail-path
sendmail_path ="/usr/sbin/sendmail -t -i"

extension=php_openssl.dll //removed semicolon

output /var/log/mail.log

Jul 27 11:09:59 ak-VirtualBox postfix/smtp[5598]: 7069320869: to=<[email protected]>, relay=gmail-smtp-in.l.google.com[74.125.129.26]:25, delay=4.9, delays=0.08/0.08/2.9/1.8, dsn=5.7.1, status=bounced (host gmail-smtp-in.l.google.com[74.125.129.26] said: 550-5.7.1 [14.98.28.24      12] Our system has detected that this message is 550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail, 550-5.7.1 this message has been blocked. Please visit 550-5.7.1 http://support.google.com/mail/bin/answer.py?hl=en&answer=188131 for 550 5.7.1 more information. kr8si13914201pbc.32 - gsmtp (in reply to end of DATA command))
Jul 27 11:09:59 ak-VirtualBox postfix/cleanup[5596]: 4AA162086D: message-id=<20140727053959.4AA162086D@ak-VirtualBox>
Jul 27 11:09:59 ak-VirtualBox postfix/qmgr[4781]: 4AA162086D: from=<>, size=2908, nrcpt=1 (queue active)
Jul 27 11:09:59 ak-VirtualBox postfix/bounce[5606]: 7069320869: sender non-delivery notification: 4AA162086D
Jul 27 11:09:59 ak-VirtualBox postfix/qmgr[4781]: 7069320869: removed
Jul 27 11:09:59 ak-VirtualBox postfix/local[5608]: 4AA162086D: to=<daemon@ak-VirtualBox>, relay=local, delay=0.12, delays=0.06/0.01/0/0.05, dsn=2.0.0, status=sent (delivered to mailbox)
Jul 27 11:09:59 ak-VirtualBox postfix/qmgr[4781]: 4AA162086D: removed

when I am submitting the form it showing email send(as per my script) but i dint receive any email in my gmail id.Is there any configuration and installation i am missing?

Any help would be appreciated

like image 714
singhakash Avatar asked Nov 01 '22 19:11

singhakash


2 Answers

In your first line, the log says specifically:

Our system has detected that this message is 550-5.7.1 likely unsolicited mail. To reduce the amount of spam sent to Gmail, 550-5.7.1 this message has been blocked. Please visit 550-5.7.1 http://support.google.com/mail/bin/answer.py?hl=en&answer=188131 for 550 5.7.1 more information. kr8si13914201pbc.32 - gsmtp (in reply to end of DATA command))

Gmail (and most other mailing services) uses a combination of the sending domain reputation, mail transfer/sending server's status (blacklisted etc), number of request frequency, number of recipients and mail content to determine if the mail is a spam.

If it determines it is not, it delivers it to the inbox, in case of medium severity it routes it to the spam folder. If the rating is really low, it blocks the mail - as in your case.

like image 159
raidenace Avatar answered Nov 09 '22 15:11

raidenace


Does the DNS on your server forward and reverse correctly? If not, that would explain why mail from your server is being treated as spam.

To see if your mail server has a glaring problem that would cause other mail servers to think it's a spammer, try sending a message from your mail server to [email protected]. This service will do a bunch of checks, and you'll get a report back with ton of information, such whether or not your mail server's DNS is setup correctly, whether your mail server's IP is on any black lists, if you have a problem with your SPF records, etc.

like image 39
mti2935 Avatar answered Nov 09 '22 16:11

mti2935