php mail function only working on local server and not on remote server - remote-server

just as the title I created a simple form in HTML
you can see it at http://thee-l.comuv.com/send.php this sends an email to me with the subject and body text specified I run this on localhost from Apache and I get in my inbox in less than a minute but I then upload it to the remote server the site and it does not email me at all
I have a gmail address so to make it easy I made an outgoing smtp server with smtp2go this was my first php-sent email, I was really happy and right away put it on the remote server and here we are
I am using 000webhost
here is my code
<?php
if ($_POST['submit']){
ini_set("SMTP", "smtp2go.com");
ini_set("smtp_port", 2525);
$to = "lsworkemail112#gmail.com";
$subj = $_POST['topic'];
$body = $_POST['message'];
$header = "From: lsworkemail112#gmail.com";
if (mail($to, $subj, $body, $header))
{
echo "Message sent successfully";
}
else
{
echo "Message sent unsuccessfully";
}
}
else
{
echo "<html>
<form method=\"post\" action=\"send.php\">
Topic: <br/><input type=\"text\" name=\"topic\"/><br/>
Message: <br/><textarea name=\"message\"></textarea><br/>
<input type=\"submit\" value=\"Send\" name=\"submit\"/>
</form>
</html>";
}
?>

I tried clicking on your link, but apparently your website is under review (possibly for mailing too much/suspected of spamming because of your testing?). Even then, linking to a .php page won't show us the code, since the server will execute it and send just the result to the browser. It's better if you copy/paste your code into the question.
Also, as #Computerish said, you may have just run into a limit on your host. How many times have you run your mail() code today?

Check your web hosting company's policies about outgoing mail. There may be a daily limit, a outright ban on it, or it may be an extra service you have to ask for. Almost all hosting companies do something to limit the use of the send() function to prevent spammers from taking advantage of their servers.

Related

cPanel mail pipe can execute file but can't send email?

I have a PHP pipe file that looks like:
#! /usr/bin/php -q
<?php
$fd = fopen("php://stdin","r");
$email = "";
while (!feof($fd))
{ $email .= fread($fd, 1024); }
fclose($fd);
$fdw = fopen("/home/user/pipemail.txt","w+");
fwrite($fdw, $email);
fclose($fdw);
mail("email#email_provider.com","You got mail","You received a new email.","From: no-reply#domain.com");
?>
When I sent an email from one of my email accounts, I noticed that the script successfully saved email header to the "pipemail.txt" file. However, it's not sending an email to "email#email_provider.com".
Does anyone knows what may be the problem? Do I have to adjust any settings somewhere?
Most CPanel send mail problems are dealing with exminmailtrap. Have you tried deleting eximmailtrap file and setting the /var/cpanel/cpanel.config eximmailtrap= to 0?
Ok I've found the reason behind the problem I described above.
It's because the IP address where my website is hosted (I'm using a shared IP) has been blacklisted by several servers as someone else abused the system. In any case, it seems like I would have to wait for the blacklists to be cleared and next time also buy a dedicated IP address.
Thanks to robobooga for posting a possible solution even though I couldn't use it. Thumbs-up to your knowledge in the field =)

How to send HTML emails with unscrubscribe functionality

My website is able to send emails to people. Now what I would like to do next is be able to send HTML emails to people who subscribe to my mailing just like I would any other normal email and should they want to unscrubscribe, there is a link to do so. I've read up on mail chimp etc but all I want is to send the HTML emails like I would normal emails. Please any guidance would be useful.
With simple HTML you can't send emails, you need PHP or any other Server-Side programming language
Example of HTML email sending with PHP:
<?php
$to = "PUT_RECIPIENT_EMAIL_ADDRESS_HERE";
$subject = "PUT_SUBJECT_HERE";
$mail_body = '<html>
<body bgcolor="#573A28" topmargin="25">
Put HTML content here with variables from PHP if you like
Variable display Example: ' . $subject . '
</body>
</html>';
$headers = "From:youremail#yoursite.comrn";
$headers .= "Content-type: text/htmlrn";
mail($to, $subject, $mail_body, $headers);
?>
to use email subscription you need a table in your database wich stores emails who subscribed to your newsletter, if a user hits "unsubscribe" you have to execute a MySQL query to remove it from your database:
table: subscribed_users(email)
SQL code to add new users to the newsletter:
INSERT INTO subscribed_users VALUES 'put_email_to_subscribe_here'
SQL code to remove users from the newsletter:
DELETE FROM subscribed_users WHERE email = 'put_email_to_unsubscribe_here'
Of course if you don't know how to use php or mysql, you need to study this two languages in order to do your newsletter subscribing.
If you don't want to learn php and mysql you can watch this page, there are some scripts that may help you, but i think you have to learn at least php in order to use them:
http://www.phpkode.com/projects/category/php-newsletter/

Emails sent through joomla go to SPAM folder

I am using the latest Joomla build for my website.
Allso we use a DNS record for having the mail delivered to our own server instead of the server on which the website is hosted.
I have used several contact form components, but every sent mail goes to my SPAM folder.
After searching hours on the web (and getting linked to this site frequently) i decided to make a new post.
It does not matter if i use the standard joomla forms, or any component.
Whenever a user fills in a form on my website, the email gets sent. The user receives a copy of its message, and i receive the message of the user. However, this message gets thrown in the spam folder, as phishing.
The sender of the mail always is: username#nameserver.i3d.net; namens; websitename
What do i have to change/enable/disable for this to work?
Thanks in advance.
Patrick.
(Sorry, I'm new to Joomla, but it uses PHP, so this may apply. Also this answer got a little long...)
It might be an issue with the email headers. A lot of email clients will automatically spam-box all mail where the address in the From: header doesn't match the envelope sender. As an analogy, you might not trust a snail-mail letter signed "Your Rich Uncle", mailed in an envelope with a Nigerian return address. Also if your envelope sender has a different domain than the one the email is actually sent from, that's another quick ticket to the junk bin. For more info about Gmail's message blocking policies (and general good practices), you can try this help page.
Here's some basic PHP email-sending code:
$to = $userEmailAddress;
$subj = $emailSubject;
$mesg = $emailMessage;
$headers = implode("\r\n",array(
"MIME-Version: 1.0"
,"Content-type: text/html;charset=iso-8859-1"
,"From: WEB_ADMIN_NICE_NAME <WEB_ADMIN#YOURSERVER.COM>" // *** 'From:' header
));
$from = "-fWEB_ADMIN#YOURSERVER.COM"; // *** envelope sender
if(!mail($to, $subj, $text, $headers, $from)){
//Some error handling...
}
On the first line I commented, you'll want to replace WEB_ADMIN_NICE_NAME with the name you want the email recipient to see (e.g. "Bill Gates"), and on both lines, replace WEB_ADMIN#YOURSERVER.COM with the actual return address (e.g. "da_boss#microsoft.com"). Note: whatever address you choose for the return address is where users' replies will be sent.
To reiterate, make sure both lines have the same return address (though the nice name can be anything you like), and make sure that the actual server sending the mail is in fact located at YOURSERVER.COM.
Lastly, I'm not sure where Joomla does its mailing, but if you're totally lost, you can try grepping with -lr for 'mail[[:space:]]*('.
there are several reasons that could make your email look suspicious to spam filters; to find out which head on to:
http://www.mail-tester.com
grab the email address and send an email from your website to it.
Then go back to the page and it will tell you what's wrong.
btw I'm struggling with the same issue,my problem being that on Joomla 2.5.9 apparently when you send html emails, a text-only copy is not added to the message, which is considered "spammish behaviour"
The problem is the i3d.net email address. My personal experience is that their network (31.204.154.0 - 31.204.155.255) is a significant source of spam and they do not action abuse reports. I suggest changing your hosting company.

Paypal IPN and mail() function

UPDATE: (2/29/12) Okay, so I've run into this same issue again for a different client on a completely different server and hosting company.
Again, having a script with just mail() sends out the email correctly with no issues. I then added code that is similar to what I have below and hooked it up with paypal IPN. Every time a new payment comes in, the IPN fires, the data gets saved to the db but the mail() function just doesn't work.
However, I ran into an interesting issue. I did a test IPN fire from paypal's sandbox with the same script and the email was sent out.
Is this an issue with paypals production IPN, perhaps the way that it posts data to the script?
Any information here would be extremely helpful since my current solution using cronjobs is sloppy.
END UPDATE
I have my paypal IPN listener configured properly since it writes all the information to the DB when a new payment comes in. Now I'm trying to setup a mail() function that sends me an email alert of a new payment.
I have done this before for another project but I can't for the life of my figure out why it's not working this time. I'm not getting any error's in the error_log and the rest of the script runs fine.
I've tested to make sure that the server actually does send mail with a standalone mail() script. I'm really lost and confused here.
Here's the code that I have:
mail('test#email.com', 'New Order', 'New Order', 'From: support#website.com');
define("_VALID_PHP", true);
require_once('../php/init.php');
$item_number = $_POST['item_number'];
$payment_gross = $_POST['payment_gross'];
$payment_status = $_POST['payment_status'];
$payer_email = $_POST['payer_email'];
$txn_id = $_POST['txn_id'];
if ($payment_status == 'Completed') {
$query = $db->query("SELECT price, id, uid FROM invoice WHERE md5='$item_number'");
$row = $db->fetch($query);
$iid = $row['id'];
$uid = $row['uid'];
if ($row['price'] == $payment_gross){
$invoiceUpdate['paid'] = 1;
$update = $db->update('invoice', $invoiceUpdate, "md5='$item_number'");
}
}
$data['iid'] = $iid;
$data['uid'] = $uid;
$data['payment_status'] = $payment_status;
$data['payer_email'] = $payer_email;
$data['payment_gross'] = $payment_gross;
$data['txn_id'] = $txn_id;
$db->insert('payment', $data);
Since your mail function returns true and your code looks correct, i think you should check the mail log because the problem might not be related to code. Try to send a mail and then check the mail log on the server...once i lost two days trying to figure out a similar problem and in the end the problem was that my mail was not accepted by other servers.
to finde your mail log you can do (from the shell):
updatedb;
locate mail.log
or
locate maillog
this assumes you are using linux, but the problem might as well exists also on windows
The code seems correct to me.
My advice:
Create a new PHP script and test the function there. Does it work?
Attempt PHP SMTP authentication with your mail server and send the email that way. Does it work? (You can use the PEAR Mail Package or any other valid SMTP class.)
If the above also fails then attempt to use the SMTP script with a custom service (e.g GMail) and check if emails are being sent. Here are the GMail SMTP parameters.
If all of the above fail, the problem is definitely with your hosting provider.
how about start off with a call to mail(), then gradually add the code that process $_POST to see when it breaks down? You should have sandbox testing with paypal to make this easier.
On a side note, you should send a verify message to Paypal server to check if the request is actually originated from Paypal, just for security.
Problem isn't in your PHP code, but on server-side. You might have full mail or your provider/your server has problems with SMTP server. Check configuration/Contact provider.
use phpmailer for mail tasks,
http://sourceforge.net/projects/phpmailer/
it will allow you to debug email problems easily.
If you've already tested the mail() function and it sends then I don't think it's anything to do with your mail settings. One word of advice, however, is that you need to be careful with the e-mail addresses you put into the mail() function. A lot of hosting providers nowadays prohibit you from sending e-mails from domains that aren't officially registered (so test#email.com would not work - it needs to be from your domain and it needs to be a valid e-mail address you've set up - it can't be a fake address at your real domain).
If it's still not working, try manually updating the php.ini settings:
<?php ini_set ( sendmail_from, "my_email#my_server.com" ); ?>
Once this is done try putting your mail() at the bottom of the script and feeding one variable to it. So an example might be:
mail('test#email.com', 'New Order', $iid, 'From: support#website.com');
If nothing's being sent, I suggest you re-evaluate your code to see if variables are filtering through your if statements. If all else fails, contact your hosting provider and describe to them your mail problems - it might be a server issue after all. If you're running it on localhost, then that's a different matter entirely (it's quite tricky setting up mail() on a localhost server).
Are you using this code on Windows or on Linux ?
The mail function should execute you must be linking the ipn to a duplicate ipn-handler php file or you did not properly save the changes to the server.
Otherwise it just does not make sense your code is crisp clear and if you send out the mail right on the top it should work.
Now if you are on Windows mail() usually isnt the best choice as Windows lacks default 'sendmail'.

Sending form without mail client

everubody! can you help me with my trouble? I'm trying to create form for filling resume. User should not use mail client to submit form. How can I realize this idea on javascript or PHP?
First: You need a server based script. Without any server interaction, no mail can be sent.
PHP has a mail() function and it works very well, if your server administrator enabled it.
Very simple example:
<?php
// The message
$message = "Line 1\nLine 2\nLine 3";
// In case any of our lines are larger than 70 characters, we should use wordwrap()
$message = wordwrap($message, 70);
// Send
mail('caffeinated#example.com', 'My Subject', $message);
?>
If mail() is disabled, you need to connect a SMTP server with correct credentials and then you can send mails via this connection.
This function is implemented in the emailer module of phpBB2 e.g.
Good luck!
If the form as a file upload... You can just upload the cv to the webserver and then use your application to send an Email using your account.