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.
Results 1 to 7 of 7
  1. #1
    New Coder
    Join Date
    Oct 2013
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post

    PHP Mailing script for my website.

    Hey, I'm new here and I'm not that great at coding. I hope someone can help me out with this:
    Code:
    <?php
    
    if(!$_POST) exit;
    
    $email = $_POST['email'];
    
    
    //$error[] = preg_match('/\b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b/i', $_POST['email']) ? '' : 'INVALID EMAIL ADDRESS';
    if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*" ."@"."([a-z0-9]+([\.-][a-z0-9]+)*)+"."\\.[a-z]{2,}"."$",$email )){
    	$error.="Invalid email address entered";
    	$errors=1;
    }
    if($errors==1) echo $error;
    else{
    	$values = array ('name','email','message');
    	$required = array('name','email','message');
    	 
    	$your_email = "Blakenic2012@yahoo.com";
    	$email_subject = "New Message: ".$_POST['subject'];
    	$email_content = "new message:\n";
    	
    	foreach($values as $key => $value){
    	  if(in_array($value,$required)){
    		if ($key != 'subject' && $key != 'company') {
    		  if( empty($_POST[$value]) ) { echo 'PLEASE FILL IN REQUIRED FIELDS'; exit; }
    		}
    		$email_content .= $value.': '.$_POST[$value]."\n";
    	  }
    	}
    	 
    	if(@mail($your_email,$email_subject,$email_content)) {
    		echo 'Message sent!'; 
    	} else {
    		echo 'ERROR!';
    	}
    }
    ?>
    I do not understand what is wrong with the code and the php server is functioning on the host.

  • #2
    New Coder
    Join Date
    Oct 2013
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Forgot to mention the error,
    When I press send on the forum it shows this code.

  • #3
    New Coder
    Join Date
    Oct 2013
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Bump, can someone please help me.

  • #4
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,090
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Blakeo View Post
    When I press send on the forum it shows this code.
    Shows what code?

    Do you mean the php source code? - In that case your server either does not have php or it is broken.

    Perhaps you mean an error message? - IT would be really helpful if you displayed it in that case don't you think

    Bottom line is the less help you give people here, the less help they will give you back.
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • Users who have thanked tangoforce for this post:

    Blakeo (10-13-2013)

  • #5
    New to the CF scene
    Join Date
    Oct 2013
    Location
    Sweden
    Posts
    5
    Thanks
    0
    Thanked 1 Time in 1 Post
    just to add.... you can use VALIDATE_EMAIL function in php, instead of preg match

  • Users who have thanked F4nt0m for this post:

    Blakeo (10-13-2013)

  • #6
    New Coder
    Join Date
    Oct 2013
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Quote Originally Posted by tangoforce View Post
    Shows what code?

    Do you mean the php source code? - In that case your server either does not have php or it is broken.

    Perhaps you mean an error message? - IT would be really helpful if you displayed it in that case don't you think

    Bottom line is the less help you give people here, the less help they will give you back.
    Thank you both for your help.
    When I put some test settings into the mailing script, click submit on the next page it shows the code exactly as the .php file contains.
    Also I was told to upload a php file to test if it works and this is the result:
    http://tgcalliance.net16.net/Untitled-1.php
    or I can include an image if you prefer.
    Thanks :-)

  • #7
    New Coder
    Join Date
    Oct 2013
    Posts
    13
    Thanks
    2
    Thanked 1 Time in 1 Post
    Just bumping this thread with some more information, hopefully someone can help me.
    I have talked to the host and they say that the email PHP scripts are allowed but they said my script can easily be abused and they suggest I fix it up so I don't get spammed.
    Same issue though I am still having that I mentioned in the original post. I think I know what they mean about it being easily abused. But I can just use Captcha so I'm not too agitated about the easily abused script.


  •  

    Posting Permissions

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