PHP mail() fails to send email, no page errors. SMTP - php

Below is a basic block of code that should send an email upon someone landing on the page. When I visit the page, I get zero errors, however the email never arrives in my inbox. Any help would be appreciated, as I feel it has something to do with my SMTP server being remote.
ini_set('SMTP','myServer');
ini_set('smtp_port',25);
If (isset($_GET["email"])) {
$email = $_GET['email'];
$to = 'group1#myOrg.org';
$subject='Internal Password scam';
$message = "$email clicked on the link and landed on the page.";
$headers = 'From: donotreply#myOrg.org' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
Some other information-
server: win64 2008 R2 Ent (Sp1)

For my particular problem it had nothing to do with the code. The issue had to deal with permissions set on the account that the emails were being sent to. My personal email wasn't allow to receive this type of email, the netadmin's email account used as $to and the emails went through just fine.

Related

php mailer is not working hotmail

<?php
$to = 'xyz#hotmail.com';
$subject = 'the subject';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = 'From: acb#gmail.com' . "\r\n" .
'Reply-To: acb#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = 'hi hello';
mail($to, $subject, $message, $headers);
echo 'mail sent';
?>
As I am sending mail using above code .. it is working fine ..
but mails are not going to hot mail...
can anyone help me in this please
This can be a plethora of things. One of the more common ones is that you are telling them you are sending mail from a gmail account but are not actually connecting to them from a gmail server.
If you could provide us with more information (specifically, lines concerning delivery from your mail.log) we could help better but most likely it is either that you aren't allowed to send mail for gmail and/or that your server is marked as "bad" by hotmail.
The hotmail spam filter stopped it, and with good reason. Advise i can give you:
Send it to yourself, and see the raw message. You may find that the From: address has changed and differs form the Reply-To:. To avoid that, send the email via SMTP instead.
If the domain you send from has a SPF DNS record, that may help. Spam filters use this to look up the authenticity of emails that claim to come from a certain domain.
This is why the #gmail.com address you used is certainly not going to pass through..

email not going through using the mail() function

I've got a form page on my website where the user has to enter his email ID. As soon as he does that an email should get triggered to him. I've used the mail() function but the email isn't going through. This is on a remote server. Am I missing out on something? Below is the PHP code that I'm using.
<?php
$to  = 'xyz#gmail.com';
$subject = 'Demo mail';
$message = 'This is a demo mail. Please reply to make sure the mail communication is okay.';
$headers = 'From: abc#gmail.com' . "\r\n" .
'Reply-To: abc#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
if (mail($to, $subject, $message, $headers)) {
echo("<p>Email successfully sent!</p>");
} else {
echo("<p>Email delivery failed</p>");
}
?>
 
The output is Email delivery failed!
What is it that I'm supposed to do apart from this? Thank you in advance!
mail() function relies on email configuration of the server the program is running on. You should take a look at your server email configuration, or use a library in order to hook up with an external SMTP service, like Gmail or one of your email servers. I recommend the Swift email library, which is well known, it's thoroughly tested and has a great community behind:
http://swiftmailer.org/
check php.ini config file for SMTP connection or add ini_set("SMTP", "IP_ADDRESS"); in your script.
you can also wrap your script with a error handler to debug the SMTP connection.

PHP mail() sends header with dedicated server domain

When I send mail via PHP's mail() it sends the wrong header information...
$to = 'mypersonal#gmail.com';
$subject = 'the subject';
$message = 'hello, hi :)';
$headers = 'From: Support <support#site.com>' . "\r\n" .
'Reply-To: From: support#site.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
in my gmail it shows
Support via mydedicatedserver.dediprovider.com
How can I configure PHP mail() to send my domain name?
mail() is already sending your domain name.
Gmail sometimes displays that message when Google is not familiar with your server and the hostname of your server does not match the domain name you're sending e-mail from. It's an anti-spam/anti-phishing measure.
Add proper SPF records to your domain. If the server is under your control, try changing its hostname to something that includes your domain name, like server1.site.com. Follow all other advice listed in the link below. Even then, there is no guarantee that Gmail will drop the message right away. In my experience, that message goes away after a while when Google becomes familiar with e-mails from your server and decides that none of them are spam. But Google seems reluctant to disclose exactly what is required, probably because they don't want spammers to get too clever.
See: https://support.google.com/mail/bin/answer.py?hl=en&answer=1311182
Also, the Reply-To: From: header is wrong.

Sending email from domain different than primary? Possible?

this may be a noobish question. I'd like to know if I can send emails from the server that say, domain1.com is associated with, as coming from domain2.com and also having the origin show as coming from domain2.com?
The reason I'd like to do this, is because I have an application I'm developing and would like to send emails from the domain, for example - maildomain.com instead of coming from domain.com
Emails are being sent with php's mail function.
Yes, you can:
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example-two.com' . "\r\n" .
'Reply-To: webmaster#example-two.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
You should set up some things, so the receiver doesn't mark it as spam though:
Set up DNS MX records with low priority for the receiving domain, pointing to sending server
Setup correct reverse DNS entries for sending server
..
The "From" address in an email is entirely arbitrary. As long as you have permission to submit mail to a server's queue, you can put any From address in it that you want. president#whitehouse.gov, julian#wikileaks.org, etc.
To do this with PHP's mail() function, use *$additional_headers*. For example:
$to = "whoever#example.com";
$subject = "This is an example!";
$message = "Hello,\n\nThis is message body.\n\nIsn't that nice?\n\n";
$headers = "From: El Presidente <president#whitehouse.gov>\r\n"
. "X-foo: bar\r\n";
$result = mail($to, $subject, $message, $headers);
Possible? Yes is sure is. See the below example from PHP.net. However, I'm going to put a little piece of fine print here, as I think you might run into some trouble, and I want to make it easier for you in the future. ;) Your current webhost may block this, I've never seen it, but I've heard it can happen. Also, there is a thing called SPF, or Sender Policy Framework, that is a DNS record that you can set to determine what servers can send on your behalf. Many servers that could receive your mail, and especially GMail check for valid SPF. All you have to do is add a TXT record on your name server for domain.com. It should look something like this: v=spf1 mx a:maildomain.com -all. This says any records that have an MX record set up, and the IPs that are resolved from maildomain.com are valid 'non-spam'. Also, you will to fail any other mail origin.
<?php
$to = 'nobody#example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster#example.com' . "\r\n" .
'Reply-To: webmaster#example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
If the mail server is an open mail relay then yes, you can send from a different domain. It is of course seen as a vulnerability as spammers can use it to send out junk mail. The configuration of the mail server to get this functionality depends on its platform but you can usually test a server's ability to freely relay messages by telneting to the server on port 25 and doing an ehlo test.

Email form isn't sending

I have an email form that isn't sending out an email to the recipient or a copy to the client. The form can be found at www.kelcos.co.uk/contact and the files associated with this are:
/index.php
/jquery.js
/sendemail.php
/submitform.php
/thanks.php
/verify.php
I have used this form on other websites http://www.bowlesgreen.co.uk/contact/ and http://www.arbortectreecare.co.uk/contact/ and it works fine - the only difference is that these other sites use my usual hosting provider and for the one that won't send I'm working through the clients hosting provider, which I can only presume is what is causing the problem.
I have contacted the hosting and so far we have eliminated a few things such as:
'The limitation to our systems is that the emails sent using scripts will be blocked if they are not going to or coming from an email address setup on the web hosting account. - so I am now sending the form to an a kelcos.co.uk address, but still no joy.
PHP/ASP was originally disabled, but now has been activated
the mail() script is enabled
I would really appreciated any advise any of you could offer.
Thanks
No, http://www.bowlesgreen.co.uk/contact/ doesn't work fine as you said. Firebug reports: POST http://www.bowlesgreen.co.uk/projects/wp/wp-content/themes/bowlesgreen/contactform/sendemail.php 404 Not Found
Your forms are submitting to the wrong URL.
Is Qmail available on the server? Are you setting the headers properly?
Try something like the following:
putenv ("QMAILUSER=myuser");
putenv ("QMAILNAME=My Name");
putenv ("QMAILHOST=mydomain.com");
$headers = 'From: My Name <myname#mydomain.com>' . "\r\n" .
'Reply-To: My Name <myname#mydomain.com>' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail_to = 'myemail#myemail.com';
$subject = "Testing email";
$body = "This mail is a test";
mail($mail_to, $subject, $body, $headers);
And see if you receive an email!
try these
http://forum.codecall.net/php-forum/28696-php-contact-form-isnt-sending-out-email.html
http://www.astahost.com/info.php/Php-Send-Email-Problem_t2259.html

Categories