PHP Mail will not process ".com" - php

I know this is weird, but when a ".com" is added to the subject or body text to send PHP mail (like - xyz.com), the mail will not send. It's a problem with this hosting company (ipage) but i want to see if their is something i can do in the script itself, because it's a CMS of mines and i would like to keep generalized for everyone who uses it.
script is simple and as follows:
function confirmEmail($username, $email, $confirm_code) {
$sitename = str_replace(".com", " .com", site_name);
$subject = "Your confirmation link here";
$headers .= 'To: '.$username.' <'.$email.'>' . "\r\n";
$headers .= "From: ".$sitename." <".support_email.">". "\r\n";
$message = "Your Comfirmation link \n
Click on this link to activate your account \n
".root."/confirm.php?confirm=$confirm_code";
$message = wordwrap($message, 70);
$sendmail = mail($username,$subject,$message,$headers);
if ( $sendmail ) {
return true;
} else {
return false;
}
}
Now as you can see, i replace the ".com" with " .com"(note the space at the beginning) for the $sitename variable, and that works but the problem is the "root" contains the full path to the givin site so the link is like "xyz.com/confirm.php?confirm=$confirm_code". I can't allow a space before the '.com' in the site path like
"xyz .com/etc..." because the obviously the user can't click the link from within their email.
I know this is a weird problem and I have no clue on what's going on or what to even ask the hosting to change.
*note: site_name and root are defined previously in another page, and they work fine. Also no errors are being returned.
Any ideas out there?

Your code is correct. Your workaround should not be necessary.
This is very likely a provider issue.
Don't know about your environment, but if you have not full control of your mailserver, try sending a mail with a link using telnet so you really see everything. Often spam filters etc are badly configured and don't return the correct codes.
If you don't have any luck with that I recommend switching to an external SMTP server that is well configured. You can perfectly use gmail for that if you dont send tons of mails.

Related

PHP mail() will not send a mail to an Outlook Distribution List [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
How do I prevent mails sent through PHP mail() from going to spam? [duplicate]
(6 answers)
Closed 3 years ago.
So a company I am helping out has outlook for their mail. Unfortunately, outlook seems to be very inflexible on how I can set up emails. I have added multiple domains to the outlook admin center for our multiple different sites. However, it will not let me create anything useful with the new domains.
For instance, we have "information#ourMainDomain.com" set up as an account.
I tried to create an alias on this account for "information#aSecondaryDomain.com" but then outlook gives me an error saying "information#ourMainDomain.com" already exists. Evidently you cannot use the same username even with different domains.
Fine. So i tried to create a shared mailbox - same issue. information#aSecondaryDomain.com is not allowed, because information#ourMainDomain.com exists... getting frustrating now!
So, after experimenting, trying everything, and spending 2 hours on the phone with outlook support that got me no where, i opted for my own route:
I created a Distribution Group called information#aSecondaryDomain.com, told this that senders outside the organization can send to it, added all the people that need to be involved, and gave them all send access.
This allows us to send emails as info#aSecondaryDomain.com
It allows us to recieve them here as well.
Also, i can send from outside the organization, ie from my gmail i can send to this account and it comes through, Great!
The problem is when i use php for a contact form, it WILL NOT send to the distribution group. It is not going to junk that i can see, and mail trace doesnt show it ever coming in at all. If i change the send to address of mail function to one of our main emails with the organization it comes through. If i change it to send to my gmail it comes through. As soon as i set it to the address of the distribution group, it will not come through. I see no errors on the php, it thinks it sent... but it never does.
Does anyone have an ideas? Or has anyone done this before?
The code in question is very simple...
<?
$name = $_REQUEST["name"];
$email = $_REQUEST["email"];
$subject = $_REQUEST["subject"];
$msg = $_REQUEST["msg"];
$to = "information#aSecondaryDomain.org";
if (isset($email) && isset($name) && isset($msg)) {
$email_subject = "$name sent you a message";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: ".$name." <".$to.">\r\n"."Reply-To: ".$to."\r\n" ;
$msg = "From: $name<br/> Email: $email <br/> Subject: $subject <br/> Message: $msg";
$mail = mail($to, $email_subject, $msg, $headers);
if($mail)
{
echo 'success';
}
else
{
echo 'failed';
}
}
?>
EDIT: I have no tried PHPMailer... same reuslt - it will send to my regular work address, and my personal, but not to the distribution group.

Mail ends up in junk folder - PHP contact form [duplicate]

I wrote a PHP script to send emails.
My script is like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: abc#yahoo.com' . "\r\n";
// Email Variables
$toUser = "someone#yahoo.com"; // recipient
$subject = "testing"; // subject
$body = "<html><body><p>
Example of including an image via html \<img\> tag:
<br>
<img src='../images/profile.jpg'>
<br>
My new picture
<br></p></body></html>"; // content
if (mail($toUser,$subject,$body,$headers)) {
echo "sent";
} else {
echo "failed";
}
Well, of course I use a valid email address for sender and receiver. I did receive the email, but it goes to junk mail. So I went for google research. Is it because of my "header" script problem? If it isn't, then what could cause my script to send a junk mail? Any solution?
Please try this:
$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";
mail($to,$subject,$body,$headers,"-f$from");
Perhaps the problem is that yahoo uses domainkeys verification, which will likely fail for your application given that the mail is not actually coming from yahoo's servers.
When I've once had a similar problem I looked at the headers and found out that my host uses SpamAssassin. So I googled for 'SpamAssassin score' and found a multitude of information on how to incorrectly (and thus correctly) form an email.
For example: SpamAssassin score list
1. Check mail content
As others have hinted it is probably marked as spam because your mail looks like spam.
I am not sure if you the script that you have posted is the actual one that you are testing.
If it has the actual mail body & headers, then running this message through a standard installation of SpamAssassin gives it a spam score of 4.9
X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
version=3.2.5
Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.
2. Mail server's IP
Another aspect worth checking will be the IP address of your mail server. Any mail originating from dynamic IP addresses will potentially be considered as SPAM.
3. Blocklists
Also check if your IP address is listed in one of the block lists. To start with please check your IP address with http://www.spamhaus.org/lookup.lasso.
Use mxtoolbox.com to check the servers IP to be blacklisted or not. As well this website can help you with a couple of email related checks.
Of course there are a long list of checks running inside spam filters. As already suggested, check the email headers for details about the spam filters rating of the spam email.
Hope that helps!
**This Works Perfectly fine for me**
$to="reciever#reciever.com";
$subject="This is Your Message";
$from = 'Sender <noreply#sender.com>';
$body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
$headers = "From: " .($from) . "\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($from) . "\r\n";;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
mail($to,$subject,$body,$headers);
I was having the same problem:
The problem is that when you specify content-type before the "From:" part , the mail comes as a spam.
But if you specify "From:" before the content part it comes as a normal mail and makes you smile and curious.
As schnalle said, one problem surely is that the smtp server that you use to send the email and the one thet you specify as From, is different.. the from's domain whould be the same that the server youre running on.
So, you can use the yahoo server to send the email (check if they allow the smtp remote connection, but i guess they do) connecting by smtp, and this will solve 1 problem.
Another one is the html contents without the alternative plain text contents, but, this one is less important.
I suggest you phpMailer, free and open-source php class to send email, easly to use (i use it event o send mail through gmail server)
On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
Make sure you send your e-mails from an existing account on your server/domain.
Make sure you have the reply-to address in your header.
These are the basic things you can try.
if your website domain is mydomain.com then in From headers make sure to use someone#mydomain.com
Remove the Content-type: text/html and add $headers .= "X-Priority: 2\nX-MSmail-Priority: high"; to get rid of Spam. This method has been tried and tested.
the problem is, the server you're sending the mail from is not a yahoo server. most spam filters check if they match, otherwise it would (and is - or was) possible to easily fake the sender. ever wondered why you get spam from bill.gates AT microsoft.com or your own mail address?
You've got two solutions:
use Yahoo's SMTP using abc#yahoo.com credentials to send mail from abc#yahoo.com;
use other from, with your own domain;
You can try the mail class and test file that I have created here. I have tested the files and can send emails to my hotmail and gmail under a different mail name. The main reason why the emails are mark as junk is because the structure (both header and message) is not correctly done. In most cases, it is the line feed that is causing the problem.
I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)
You can check the files here..

Sending mail on PHP using LAMP

I have been trying for awhile now to send mail using PHP, and I can't seem to get it to work.
I looked at the tutorials, and they make it seem simple enough. Yet, it seems to actually require more work than what is mentioned. Through research (to make this short), it seems that instead of the "From: " header actually having the address I give to it, it seems that... sendmail replaces it or something with daemon#ubuntu? Ok, even if I don't include a header I still get spam from my gmail account from the daemon#ubuntu thing (I am running ubuntu on a vm, and sending mail to my gmail account). I guess this could explain why I incessantly get errors when I try to send mail saying how there is an error in the "MAIL FROM command".
So before I get myself involved with messing around with sendmail, is this the (likely)culprit of the daemon#ubuntu nonsense? The tutorials make mention of having things like sendmail, but they really don't go into any details of what to do with them. I did make sure that sendmail is being used in my php configuration file.
I have heard of alternative mail servers like PHPmail or something like that. I really don't want to get involved in installing and configuring more software unless I really have to. So unless you guys really think sendmail isn't worth it, I would prefer advice on sendmail if it is the problem.
Thank you for your time.
edit: I am using the PHP mail() function on an Ubuntu vm by VMware Player.
So someone wanted to see my code. I somewhat wanted to avoid this simply because I tried many different possibilities. I will just include what I have in my file right now:
<?php
$myEmail = "#####gmail.com";
$fromAddr = $_POST['sender-email'];
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: $fromAddr\r\n";
$headers .= "'X-Mailer: PHP/'" . phpversion() . "\r\n";
$message = $_POST['message'];
$status = mail($myEmail, $_POST['subj'], $message);
if($status) {
echo "Your message has been sent, " .$fromAddr. "!";
}
else {
echo "An error occurred while trying to send the mail.";
}
?>
The MIME type thing, and Content-type thing I added later on. I have tried this without them. I have also tried sending mail without using any headers at all, and still apparently get the daemon#ubuntu thing. Also, I edited out my e-mail address to post the code on here. Ok I guess I should add this too: I am getting the data from an HTML form from another page. On submit, I come to this php page where it grabs that data and then sends the email (this isn't for anything professional, I am just doing this to learn more about web stuff).
Postfix is a very easy to use and install email server, in my experience. You need an email server installed and configured before you're able to send email on your localhost.

Odd behaviour with links in PHP Mail function

I'm currently trying to get links working in emails sent via the PHP mail function. Here is my code - I've also included some things I've tried (commented out along with notes):
$to = "test#testing.com";
$subject = "Testing email";
//$body = '<strong>This is strong text</strong>'; <-- Works
//and the text is correctly emphasised.
//$body = 'Link Test'; <-- Works
//but without http:// at the start makes the link relative to the server root
//$body = "<a href='http://www.yahoo.com'>Link Test</a>"; <-- Does not work
//$body = "Link Test"; <-- Does not work
$body = 'Link Test'; //<-- Does not work
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "From: Steven Parler <". $to . ">\r\n";
$headers .= "X-Mailer: PHP/".phpversion() . "\r\n";
if (mail($to, $subject, $body, $headers)) {
echo("<p>Message successfully sent!</p>");
} else {
echo("<p>Message delivery failed...</p>");
}
As can be seen html is working without links, and links also work providing I don't include "http://" in the link itself. If I do include the "http://" then no email is received / sent at all (I'm unsure which as the mail() command returns true to say it was sent).
I'm not really sure why this isn't working. Could it be some setting that needs changing on my webhost's server? I'm on windows shared hosting.
Thanks in advance for any advice anyone can give me - been pulling my hair out over this lol. :)
Don't build MIME messages by hand. It's just too painful and fragile. Use something like PHPMailer or SwiftMailer to do it for your automatically. You provide the HTML, they'll provide the appropriate headers
I completely agree with #Marc B.
Here are a couple more options: XPertMailer, Zend_Mail, Rmail, HTML MIME MAIL
I've worked with all of these but since I'm working mostly with the Zend Framework I'm lately using Zend_Mail.
Having said that, your hosting provider might be blocking your emails because they might think it's SPAM. Try generating valid html markup that passes validation and see if that helps.
That's very odd behaviour, I'd expect the last 2 to work perfectly. I tried this out on my server, and mail($email, $subject, $body, $headers); worked perfectly with a $body of
text text text: \n http://website.com.
Perhaps it's a setting somewhere? If you're using awardspace, they require a from header to be used, and the mail sent from an e-mail registered with them. Other hosts might have a similar procedure.
Thanks for all the responses. I finally got around it by using the SMTP feature of Swiftmailer which correctly created the email with links.
Out of interest I tried the code I used in my original post again... but this time I used a random web address (http://www.trustedreviews.com). The email arrived... I then tried a lot of other web addresses - google.com, hotmail, yahoo.co.uk etc and they all arrived. Changed it back to (http://www.yahoo.com) and lo and behold the message did not arrive again. So it seems out of the millions of web URL's there are I chose the one that my webhost has decided to block lol...
That said the yahoo link does arrive ok using the smtp function of swift mail; it's only with the php mail function it doesn't seem to work. I guess I'll contact them and ask why it's blocked. I'll most likely stick with using the smtp method as at least it seems like it bypasses any restrictions.
Thanks again for everyone's time and help :)

Using PHP mail( )

I have a php mail script which works perfectly on a one host. However, when I attempt to use the same script on a network solutions host, the function returns true but no email ever sends.
//get mail function data
$case = $_POST['case'];
$to = addslashes(strip_tags($_POST['to']));
$message = addslashes(strip_tags($_POST['message']));
$subject = addslashes(strip_tags($_POST['subject']));
$message = addslashes(strip_tags($_POST['message']));
$from = "confirmation#website.co";
$headers = "From: $from\r\n";
//send email
if (mail($to,$subject,$message,$headers)){
//formatting for error message
$emailSent = "block";
$emailFailed = "none";
}
else //if the email fails to send
{
$emailSent = "none";
$emailFailed = "block";
}
?>
Does anyone know if different hosts require specific info in mail script?
This is a question for Network Solutions customer support. Sending mail from shared hosting servers is usually well locked down -- if they allow it at all, it's throttled. Also, calling mail just means the message was successfully passed to sendmail, not that the mail ever left the server. It could be sitting in a queue to be sent, it could have bounced for a million reasons beyond your control, etc.
Some hosts have this issue. On mine (Mosso), I had to adjust the last parameter (from) like so:
mail($to, $subject, $message, $headers, "-f".$from)
May not be the solution for NetSol but worth a try. I know some hosts disable the script and require using the smtp class to send mail.
This is assuming, of course, everything is correct with your DNS and MX records. If you're trying to send from an account that is different than the domain being sent from, some providers will automatically block that.
It maybe that they have not enabled php mail, but ask the host for specifics.
Looking at your code it is not cleaning the input sufficiently. take a look at the is_forbidden function here:
http://thedemosite.co.uk/phpformmailer/source_code_php_form_mailer_more_secure_than_cgi_form_mailers.php

Categories