Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 16
  1. #1
    New Coder
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 1 Time in 1 Post

    PHP's mail function not sending mail...

    On another website I used PHP's mail function to mail a simple contact us type form to an admin person. Well, I have need of doing it with my current job. I created a simple contact us form and all it has to do is email it's contents to me (for testing of course).

    Well, it's not returning any errors whatsoever but it's also not sending the email.

    Here's the contact us form page... http://www.oasisgamingusa.com/testla...us_layout9.php

    Here's the code for the actual page that has the mail function...
    Code:
    <?php
    	function handleform()
    	{
                  ......... other code here ..........
    	} // end if action == 2
    		else
    			if(!$action)
    			{
    				// email the comments from the contactus page to
    		  		// the default email address
    				//$toaddress = "marketing@oasisgamingusa.com"
    				$toaddress="Sean.Meyer@oasisgamingusa.com";
    			
    				// To send HTML mail, the Content-type header must be set
    				$headers  = "MIME-Version: 1.0\r\n";
    				$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    				$headers .= "From: website@oasisgamingusa.com\r\n";
    
    				$subject = "Comments/Inquiry";
    
    				$mailcontent = "
    					<html>
    						<head>
    							<title>Comment/Inquiry From Website User</title>
    						</head>
    						<body>
    							<table>
    								<tbody>
    									<tr>
    										<td colspan='2'><h1>Comment/Inquiry From Website User</h1></td>
    									</tr>
    									<tr>
    										<td><strong>Name:</strong></td>
    										<td>$name</td>
    									</tr>
    									tr>
    										<td><strong>Email:</strong></td>
    										<td>$email</td>
    									</tr>
    									<tr>
    										<td><strong>Phone:</strong></td>
    										<td>$phone</td>
    									</tr>
    									<tr>
    										<td><strong>Comments/Inquiry:</strong></td>
    										<td>$comments</td>
    									</tr>
    								</tbody>
    							</table>
    						</body>
    					</html>";
    
    				if(!mail($toaddress, $subject, $mailcontent, $headers))
    				{
    				  	echo "<p class='articlecontent'>There was an error submitting ";
    				  	echo "your comments.  Please try again later.</p>";
    				  	exit();
    				}
    				
    				echo "<p class='articlecontent'>Thank you!  We appreciate your ";
    				echo "comments and will contact you back if needed.</p>";
    			} 
    
    			}
    ?>
    That code actually does some other stuff as well but the mail function code is in the lower half.

    Anyone know if there's something else that needs to be set up and where I might found out how to set it up?

    Anyone have any other ideas for me on what might be wrong?

    Thanks

  • #2
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Maybe I'm stupid but where abouts is the mail function used in that code to send the mail?

  • #3
    New Coder
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 1 Time in 1 Post
    The mail function is towards the bottom of that code section. It's about 13 or so lines up from the bottom. Part of an if statement to see if it gets an error while sending.

    I'm thinking the problem is actually on our server and the way the mail server is configured. I believe that our network guy said that it was set up in a DMZ. I'm not really sure what that means but evidently it makes a little more difficult to send mail via our mail server.

  • #4
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    PHP Code:

    if(!mail($toaddress$subject$mailcontent$headers))
                    {
                          echo 
    "<p class='articlecontent'>There was an error submitting ";
                          echo 
    "your comments.  Please try again later.</p>";
                          exit();
                    } 
    I'm not exactly a php seasoned pro but that almost looks to me like your saying what the code should do if mail is not sent, but not actually attempting to send it. I may well be wrong but try simplifying the code a little first just to rule out the possibility that the code could be wrong, then you'll know for sure that it's the server.

    PHP Code:

    $toaddress
    ="Sean.Meyer@oasisgamingusa.com";
    $subject "Comments/Inquiry";
    $mailcontent "Just testing to see if this works...";

    if(
    $_SERVER['REQUEST_METHOD'] == 'POST')
       {
         
    mail($toaddress,$subject,$mailcontent);
       } 
    That's probably the quickest way to find out if your code is dodgy.

  • #5
    New Coder
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 1 Time in 1 Post
    Ok, I'll give that a try and see what happens.

    At one time I did try it without the if statement and just had the mail function and it still acted like it sent, giving me no errors whatsoever, but I didn't receive anything.

    Anyway, my day is done so I'll try this out tomorrow.

    Thanks for the input though.

  • #6
    New Coder
    Join Date
    Oct 2006
    Posts
    82
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Good luck with it, and if you have time to let us know how it goes then I'd appreciate it

  • #7
    Regular Coder
    Join Date
    Apr 2003
    Location
    Montreal, QC
    Posts
    340
    Thanks
    3
    Thanked 2 Times in 2 Posts
    Quote Originally Posted by littlejones View Post
    I'm not exactly a php seasoned pro but that almost looks to me like your saying what the code should do if mail is not sent, but not actually attempting to send it. I may well be wrong but try simplifying the code a little first just to rule out the possibility that the code could be wrong, then you'll know for sure that it's the server.
    The code:
    PHP Code:
    if(!mail($toaddress$subject$mailcontent$headers)) 
    will actually try to send the mail, then, if it is successful will return a false, (because of the ! ), and if unsuccessful return a true and post the error message.

    However, the solution of simplifying the code will help a lot because with the current structure you won't see the error messages.
    Search for Laughter or Just Search?
    GiggleSearch.org
    Blog: www.johnbeales.com
    All About Ballet: www.the-ballet.com

  • #8
    New Coder
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 1 Time in 1 Post
    Well, I tried the simpler solution above as well as a couple of other ideas I had and still I receive no emails. After talking more to our MCSE guy more I'm almost positive the problem is not with my code but with how things are set up here internally (ie with the mail servers and firewall and what not). We're going to work on it and see what we can come up with here.

    Thanks for all the help though everyone. I appreciate it.

  • #9
    Master Coder
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,538
    Thanks
    8
    Thanked 1,093 Times in 1,084 Posts
    Don't forget to check your bulk bin (junk bin/spam bin) whatever yours
    is called ... sometimes emails get in there and you forget to look.

  • #10
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    also, subjects are known for sending non-spam emails to junk inbox, try changing your subject

  • #11
    New Coder
    Join Date
    Sep 2006
    Posts
    48
    Thanks
    0
    Thanked 1 Time in 1 Post
    Thanks for the info. I'll definitely check those things just to make sure.

  • #12
    Regular Coder
    Join Date
    Jan 2006
    Location
    Finland, Hollola
    Posts
    285
    Thanks
    8
    Thanked 0 Times in 0 Posts
    firstly you can try to make a new script like this and execute it once:

    Code:
    <?php
    mail("yourmail@mail.com","subject","message");
    ?>
    Remember to change the yourmail to the correct so you can see whether it succeed or not.

    Check also that mail() function is enabled in the php.ini and check out also that you can SMTP server established.
    PHP 5 & MySQL 5 (Y)

  • #13
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    in addition on checking if the mail sends
    create a new document named testmail.php
    with this is
    PHP Code:

    <?php
    $time 
    time();
    $to "you@youremail.com";
    $subject "test subject";
    $body "this should be sent to $to, with the subject line of $subject at $time" ;

    mail($to$subject$body);
    if (
    mail($to$subject$body))
    {
    echo 
    "the test mail was sent";
    }
    else

    echo 
    "the test email failed to send";
    }
    ?>
    this will tell you if the mail was sent, dont forget to change the email again :P

  • #14
    Senior Coder rafiki's Avatar
    Join Date
    Aug 2006
    Location
    Floating around somewhere...
    Posts
    2,046
    Thanks
    19
    Thanked 42 Times in 42 Posts
    heres a page with the exact code on tripod
    http://members.lycos.co.uk/jaysphp/testmail.php
    you may need to view source coz of the ads

  • #15
    fan
    fan is offline
    New Coder
    Join Date
    Jan 2003
    Location
    Romania
    Posts
    72
    Thanks
    1
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rafiki View Post
    heres a page with the exact code on tripod
    http://members.lycos.co.uk/jaysphp/testmail.php
    you may need to view source coz of the ads
    rafiki, how can you view the source of a PHP page (read server-side generated and passed to the browser) in a browser?

    I guess that thing doesn't send you an e-mail everytime someone goes to the page, does it?


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •