This seems kind of weird, and there is nothing I could find about.
Sending this via php -a
echo mail("xxx#xyz.com", "message from xyz.com", "this is a message from xyz.com");
Results in no message received at the other end, but if I remove all the periods from the subject AND message as in:
echo mail("me#me.com", "message from xyzcom", "this is a message from xyzcom");
Then the message is successfully received successfully.
I understand that a terminating period is allowed, so how are other periods accomplished?
Note that BOTH of the above return TRUE from PHP mail();
The comments provided me some hints to what was happening and my immediate problem was solved by simply whitelisting the source mail IP address.
And, that only works because the PHP mail destination is always the same address (it is contact page data).
I also realize that I need a more sophisticated email arrangement than basic PHP mail, so I will install a good smtp server which will alleviate problems like this.
Related
Having a weird issue here friends.
I have installed phpMailer for my codeigniter application using this link https://github.com/ivantcholakov/codeigniter-phpmailer
It seems to be working. But when first installed I provided sample email for sender... johny#domain.name
That worked.
But since, It only works with this sender email address.
If lets say for instance I use andy#domain.name it is not sending.
Result is true as successful, but no messages come through.
This works...
<code>
$result = $this->email
->from('johny#*****.com','Email from tester')
->to('samantha#*****.com') // some other domain than sender
->subject('This is test')
->message('Test message')
->send();
var_dump($result);
</code>
This doesn't...
<code>
$result = $this->email
->from('mark#*****.com','Email from tester')
->to('samantha#*****.com') // some other domain than sender
->subject('This is test')
->message('Test message')
->send();
var_dump($result);</code>
Both result in success, but only first one successfully sends the message.
Also there is no errors in server error.log
Has anyone ever run into this? What was the solution?
Thank you.
So to update, apparently there is nothing wrong with above code.
But there was some sort of massive lag on my mail server or my mail client app.
All the messages I had missing got to my junk mail inbox hours later.
I still see the lag at this time, tho not as long as previously but still 10-15 minutes.
Anyway, if you get to this exact point, then first check your mail.log
on ubuntu it is located most likely in..
<code>
/var/log/mail.log
</code>
If all is well in there, then advise to search elsewhere not your code.
I suppose check your with receivers mail-provider(in case of testing it is probably yours) or your mail client. (in my case it is outlook )
I'm trying to send emails in a loop and it is working fine but it prints the result to page in one go rather one by one.
What I want is, it should print a response for every email sent. This is what I have so far:
//foreach loop
$Response = $ObjMail->send();
if ($Response) {
echo "Email Sent Successfully to $val[name] </br>";
} else {
echo "There was an error sending Email to $val[email]";
}
Depending on your $ObjMail, a "successfully send mail" generally will equate to
the sending mail server (i.e. smtp server) accepted the email or
the mail() function got called (actually read the doc, especially the return value part).
Email functions rarely return a very useful value, as long as the email being sent is at least somewhat plausible. It will even return true, if the email address doesn't exist, the email gets bounced, your smtp server is blacklisted, ...
The probable answer to your question: Your output is almost instantaneous by default, unless your local sendmail (the default on most hosts) call takes longer than a few microseconds, which it usually doesn't. Additionally, it doesn't say anything about the mails actually being sent. (And I assume, that you thought that was actually the case, it's not.)
My advice is, drop the stylish output and just send the mails. You can't be certain if they actually reached their target. If the $ObjMail actually returns an error, that would probably be wise to log somewhere, so that you don't repeatedly send to the same false address.
I'd like to make a form that posts data to my email.
I found the following code and it works fine except I didn't get any email from the form.
Here is the Php File
<?php
// Contact subject
$name ="$name";
// Details
$address="$address";
$id="$id";
$passport="$passport";
$issue="$issue";
$mula="$mula";
$tamat="$tamat";
$tel="$tel";
$select_dd="$select_dd";
$date="$date";
$textarea="$textarea";
$file="$file";
// Mail of sender
$email="$email";
// From
$header="from: $name <$mail>";
// Enter your email address
$to ='rodhiahazzahra#gmail.com';
$send_contact=mail($to,$subject,$message,$header);
// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}?>
Where did you try this code? Local or on a Server? Is there sendmail (or similar) installed and properly configured on your server?
Quote from PHP - Mail Function
It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination.
You should check your configuration on the server and check the mail logs and you spam-folder.
If i am not mistaken, you need to set the SMTP server before you call mail().
ini_set('SMTP','mySMTP.serv');
Cheers
Edit:
Caution
(Windows only) When PHP is talking to a SMTP server directly, if a full stop is found
on the start of a line, it is removed. To counter-act this, replace these occurrences
with a double dot.
<?php
$text = str_replace("\n.", "\n..", $text);
?>
If you just started learning, one of the basic rules is always RTM before you start using a function. here is the link for PHP Mail function http://us3.php.net/manual/en/function.mail.php
first of all this question is for personal knowledge, and not for any kind of attack :) hope you'll believe me and give me some hints.
I'm trying to reproduce an example of mail header injection I found (link-> http://www.phpsecure.info/v2/article/MailHeadersInject.en.php). Basically it uses a form to get 3 parameters (subject, message and sender mail), then these parameters are sent with POST method and used in the php mail() function to an admin's mail.
Everything works fine, each mail is sent without problem but when I try to inject some other parameters as Cc, Bcc etc the trick doesn't work: neither \r & \n nor %0A & %0D are interpreted as CL and RF. For example, if I put my#mail.com%0ACc:foo#bar.com in the "From" field, in "my#mail.com" inbox I'll find the mail, with the same "From" field as it was sent (my#mail.com%0ACc:foo#bar.com). Does php or does input tag encode (or unencode) properly the input? How can I make it work?
Hope you can understand my bad english, thanks in advance, best regards.
ps: the article I linked is dated 2005, recently I've found that a similar bug with http headers splitting using php function "header()" was fixed, so I thought that they fixed email headers injection problem too.. But I can't find anything on the web that confirms this.
______________________EDIT________________________________________
Example working, modifying header within php code:
$to = "admin#mail.com";
$sub = "this is the subject";
$msg = "this is the message";
$header = "From: foo#foo.com"."\r\n"."Cc: bar#bar.com";
$if(mail($to, $sub, $msg, $header."\n")){
echo "sent";
}else{
echo "error";
}
The email is correctly received both from foo#foo.com and bar#bar.com
Examples NOT working (this is the problem I'd like to solve with your help):
Once I send the mail with "send" button, only foo#foo.com will get the e-mail, and in the "from" detail (inside the mail) I'll find (1st case) foo#foo.comrnCc: bar#bar.com or (2nd case)foo#foo.com%0D%0ACc: bar#bar.com.
I always find i need to use both \r\n in order for the headers to be sent properly.
I'm trying to sends mails in PHP. The code I used for sending a mail in CakePHP is given below. I get the message 'Simple Email Sent' in my web page but the mail is not delivered to my inbox. Am I missing something?
The values in the to, subject and link fields are set with the values entered in the user interface.
$this->set('to',$this->params['form']['to']);
$this->set('subject',$this->params['form']['subject']);
$this->set('link',$this->params['form']['link']);
$this->Email->to = to;
$this->Email->subject = subject;
$this->Email->from = 'someperson#somedomain.com';
$this->Email->delivery= 'mail';
$this->Email->sendAs='text';
$this->Email->template = 'simple_message';
//$this->Email->send(link);
if ( $this->Email->send(link) ) {
$this->Session->setFlash('Simple email sent');
} else {
$this->Session->setFlash('Simple email not sent');
}
On a Linux system, you'll probably have a sendmail script installed already, and PHP will use that. If this is what you have and it's not working, then I'd look for mail configuration problems in your Linux system itself.
On a Windows system, you'll need to configure the SMTP server you want PHP to send mail to. The normal way to do this is in php.ini. The instructions for this are here.
Unless you have set Email->delivery this should be the same for CakePHP - it should default to whatever PHP uses.
Note: If you are using your own Linux install, it could just be that your ISP is blocking port 25, which your mail server is using. In that case you'll need to configure linux to route email to your ISP's email server. Maybe this will help?
Since when is 'to' (line 4) a valid destination email address?
You need to use variable syntax for setting to 'to' line, and the 'subject' line. Those lines should read
$this->Email->to = to;
$this->Email->subject = subject;
Also, I believe there is an attribute in the Email component called error (I cannot find it in the documentation currently) that will help you debug. This may not be totally correct; I use the Email component with SMTP, and there is an attribute that gets set by the Email component called smtpError. I believe there is one called error that you can use to check for an error -- it should contain code that will tell you where your problem lies.
In case that's an incorrect statement, you can always do a var_dump( $this->Email ); after you try to send an email. That will dump the entire contents of the object, so you can see if you have set attributes correctly, and it should help you find out what the error attribute is named.