Page 1 of 1

Mail function failure :(

Posted: Sat Apr 16, 2016 3:58 pm
by Goofan
So my problem lies in that it actually isn't sending the mail to my said emails (tried several different). Neither of the Mail() functions are working for me which tells me I've done something wrong.

I tried a different code and that worked but it didn't have the same stuff as I wanted nor was it in a seperate class.

So my code is as following:

Code: Select all

public function contactForm(){
		$msg = "";
		$submit = isset($_POST['submit'])  ? true : false;
		if($submit){
			$receiver = "dommyhelp@gmail.com"; //Jepla@telia.com
			$sender   = isset($_POST['name'])  ? $_POST['name']  : null;
			$email    = isset($_POST['email']) ? $_POST['email'] : null;
			$message  = isset($_POST['text'])  ? $_POST['text']  : null;
			$subject1 = "Jepla.se";
			$subject2 = "Kopia | Jepla.se";
			$message1 = $sender ." skrev foljande:" ."\n\n" .$message;
			$message2 = "Kopia av ditt medelande " .$sender ."\n\n" .$message;
		
			$headers1 = "Från:" .$sender;
			$headers2 = "Från:" .$receiver;
			if (mail($receiver,$subject1,$message1,$headers1)){
				mail($sender,$subject2,$message2,$headers2); // sends a copy of the message to the sender
				$msg = "Mailet har blivit skickat."; //Success, Mail sent!
				var_dump($receiver ." " .$subject1 ." " .$message1 ." " .$headers1);
			}else{
				$msg = "Mailet har inte skickats."; //Failure, Mail sadly not sent
			}
    	}
		$html = <<<EOD
			<form id="ContactForm" method=post>
			  <fieldset>
				  <legend class="letter_spacing">Kontakt Formulär</legend>
						<div>
							<div class="wrapper">
								<span>Namn:</span>
								<input type="text" class="input" 
										placeholder="::Ditt namn, För och Efternamn" name="name">
							</div>
							<div class="wrapper">
								<span>Email:</span>
								<input type="text" class="input" 
										placeholder="::Din email adress" 
											name="email">								
							</div>
							<div class="textarea_box">
								<span>Meddelande:</span>
								<textarea cols="1" rows="1" 
										placeholder="::Ditt Meddelande" 
											name="text"></textarea>								
							</div>
                            <input class="button" type="submit" value="Skicka" name="submit">
						</div>
			  	</fieldset>
			</form>
			{$msg}
EOD;
			
		return $html;
	}
The result I'm getting is:

Code: Select all

string(89) "dommyhelp@gmail.com Jepla.se thomas lundqvist skrev foljande: dfsf Från:thomas lundqvist"
Which is all correct aswell as the mail adress (real dommy adress)

And then I get at the bottom:
Mailet har blivit skickat.
Which translates into "Mail sent". Which is where I'm confused because here it get's checked or so I thought atleast as to if it was sent or not.

Code: Select all

if (mail($receiver,$subject1,$message1,$headers1)){
				mail($sender,$subject2,$message2,$headers2); // sends a copy of the message to the sender
				$msg = "Mailet har blivit skickat."; //Success, Mail sent!
				var_dump($receiver ." " .$subject1 ." " .$message1 ." " .$headers1);
			}
Is there something with the Mail() function i'm unaware of?

Thanks in advance,
Thomas

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 4:01 pm
by Celauran
Have you checked your error logs? Do you know that the mail isn't being sent, or is it simply not being received? Why not capture the return value of mail() in a variable and inspect that?

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 4:09 pm
by Goofan
returning the Mail() with paramaters:
dommyhelp@gmail.com
Jepla.se
thomas lundqvist
dfsf
I get true on the boolean which sais it's sending and not receiving.
My second one is not returning true tho but that's another issue that I proberbly is missing something with (Not the consern as of right now)
And for error log I'm not getting any errors on this :/
And as said I have sent it to different emails...

Thanks

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 4:12 pm
by Goofan
Ohh and just to clarify I have checked the spam mail box aswell nothing there either :/

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 4:13 pm
by Celauran
Where are you sending from? Localhost? A web host on your domain?

If it's local, check that your mail server is running, check that the mails are being spooled correctly, sent correctly, and aren't bouncing back. In both cases, there's also the possibility that they're being rejected as spam and filtered accordingly. Check the SPF records for your domain.

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 4:14 pm
by Celauran
Also try changing the recipient to one on the local machine. If that's being received, you know it's not a code problem but a server configuration problem.

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 4:38 pm
by Goofan
It's on a hosted server not localhost. Yes checked the SPF of my emails in use.
Don't really know what you mean by spooled correctly. How can I check this?
How can I check if it's my host that is bouncing the emails going out?

Tried this out on Localhost and got this:
"Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\jeplatest\index.php on line 21"

Can't really read this so please do tell me what it means and what I can do to fix it? (Don't use Localhost at all anymore more or less allways building in a live enviroment :/)

Regards

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 5:56 pm
by Celauran
Sending mail on Windows, for all intents and purposes, isn't going to work.

On your host, you'll need to check the mail server logs. This is usually /var/log/maillog

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 6:04 pm
by Goofan
Ohh why not? Curiosity...

I get it as I need todo the domainame/var/log/maillog
Like:
example.com/var/log/maillog ??
If so then there is no file to be found.

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 6:36 pm
by Celauran
No, just /var/log. That's the full path.

Why doesn't mail work on Windows? Mostly because it relies on the sendmail subsystem which doesn't exist in Windows environments. You can make it work via SMTP, and you can install a mail server on Windows, but results are going to be pretty mixed.

Re: Mail function failure :(

Posted: Sat Apr 16, 2016 6:53 pm
by Goofan
Where do I need to write it?
Can't just send the /var/log as the URL hehe
If it helps im using one.com as the webspace and domain keeper.

Ohh that sounds strange but thanks for the info, we learn something new each day :D

Re: Mail function failure :(

Posted: Sun Apr 17, 2016 7:26 am
by Celauran
It's not something you pass as a URL. It's a log file. You need to be logged in to the system to read it. If you're on shared hosting, you're probably out of luck. Then, if you're on shared hosting, it's likely configured correctly. You said you've checked the SPF records for your domain?

Re: Mail function failure :(

Posted: Sun Apr 17, 2016 4:48 pm
by Goofan
SPF is the Spam filter of the domain that's what you mean or what do you mean by SPF?

If this is not the solution is there another way to send the input as a mail to the desired party?

Thanks once more for all the help.
Regards,
Thomas