Jump to content

Recommended Posts

Hey guys, bit of a newb here.  But I am having a brutal time trying to get the php mail() function to work with GoDaddy.  I contacted them and they said I must use their PHP gdform.php script to send out emails.  My script sends the emails from register.php and  functions.php.  Does anyone know how I can integrate godaddy's gdform.php to work with my functions.php mail() script.  Doesn't make sense to me my go daddy makes this so difficult to use a simple function.

 

Thanks in advance!!! 8)

 

 

My register.php script

 

<?php


include ('config.inc.php');
include ('functions.php');

// Those two files can be included only if INCLUDE_CHECK is defined


session_name('wkLogin');
// Starting the session

session_set_cookie_params(2*7*24*60*60);
// Making the cookie live for 2 weeks

session_start();

if($_SESSION['id'] && !isset($_COOKIE['wkRemember']) && !$_SESSION['rememberMe'])
{
// If you are logged in, but you don't have the wkRemember cookie (browser restart)
// and you have not checked the rememberMe checkbox:

$_SESSION = array();
session_destroy();

// Destroy the session
}


if(isset($_GET['logoff']))
{
$_SESSION = array();
session_destroy();

header("Location: tester.php");
exit;
}

if($_POST['submit']=='Login')
{
// Checking whether the Login form has been submitted

$err = array();
// Will hold our errors


if(!$_POST['username'] || !$_POST['password'])
	$err[] = 'All the fields must be filled in!';

if(!count($err))
{
	$_POST['username'] = mysql_real_escape_string($_POST['username']);
	$_POST['password'] = mysql_real_escape_string($_POST['password']);
	$_POST['rememberMe'] = (int)$_POST['rememberMe'];

	// Escaping all input data

	$row = mysql_fetch_assoc(mysql_query("SELECT id,usr FROM wk_members WHERE usr='{$_POST['username']}' AND pass='".md5($_POST['password'])."'"));

	if($row['usr'])
	{
		// If everything is OK login

		$_SESSION['usr']=$row['usr'];
		$_SESSION['id'] = $row['id'];
		$_SESSION['rememberMe'] = $_POST['rememberMe'];

		// Store some data in the session

		setcookie('wkRemember',$_POST['rememberMe']);
	}
	else $err[]='Wrong username and/or password!';
}

if($err)
$_SESSION['msg']['login-err'] = implode('<br />',$err);
// Save the error messages in the session

header("Location: tester.php");
exit;
}
else if($_POST['submit']=='Register')
{
// If the Register form has been submitted

$err = array();

if(strlen($_POST['username'])<4 || strlen($_POST['username'])>32)
{
	$err[]='Your username must be between 3 and 32 characters!';
}

if(preg_match('/[^a-z0-9\-\_\.\@]+/i',$_POST['username']))
{
	$err[]='Your username contains invalid characters!';
}

if(!checkEmail($_POST['email']))
{
	$err[]='Your email is not valid!';
}

if(!count($err))
{
	// If there are no errors

	$pass = substr(md5($_SERVER['REMOTE_ADDR'].microtime().rand(1,100000)),0,6);
	// Generate a random password

	$_POST['email'] = mysql_real_escape_string($_POST['email']);
	$_POST['username'] = mysql_real_escape_string($_POST['username']);
	// Escape the input data


	mysql_query("	INSERT INTO wk_members(usr,pass,email,regIP,dt)
					VALUES(

						'".$_POST['username']."',
						'".md5($pass)."',
						'".$_POST['email']."',
						'".$_SERVER['REMOTE_ADDR']."',
						NOW()

					)");

	if(mysql_affected_rows($link)==1)
	{
		send_mail(	'noreply@mygodaddydomain.com', 
					$_POST['email'],
					'Registration System Demo - Your New Password',
					'Your password is: '.$pass);

		$_SESSION['msg']['reg-success']='We sent you an email with your new password!';
	}
	else $err[]='This username is already taken!';
}

if(count($err))
{
	$_SESSION['msg']['reg-err'] = implode('<br />',$err);
}	

header("Location: tester.php");
exit;
}

$script = '';

if($_SESSION['msg'])
{
// The script below shows the sliding panel on page load

$script = '
<script type="text/javascript">

	$(function(){

		$("div#panel").show();
		$("#toggle a").toggle();
	});

</script>';

}
?>


 

 

My Mail() funtions.php script


<?php


function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}


function send_mail($from,$to,$subject,$body)
{
$headers = '';
$headers .= "From: $from\n";
$headers .= "Reply-to: $from\n";
$headers .= "Return-Path: $from\n";
$headers .= "Message-ID: <" . md5(uniqid(time())) . "@" . $_SERVER['SERVER_NAME'] . ">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Date: " . date('r', time()) . "\n";

mail($to,$subject,$body,$headers);
}
?>





 

 

 

Godaddys gdform.php

 

<?php
$request_method = $_SERVER["REQUEST_METHOD"];
if($request_method == "GET")
{
	$query_vars = $_GET;
} 
elseif ($request_method == "POST")
{
	$query_vars = $_POST;
}

reset($query_vars);
$t = date("U");
$file = $_SERVER['DOCUMENT_ROOT'] . "\ssfm\gdform_" . $t;
$fp = fopen($file,"w");

while (list ($key, $val) = each ($query_vars)) 
{
	fputs($fp,"<GDFORM_VARIABLE NAME=$key START>\r\n"); 
	fputs($fp,"$val\r\n");
	fputs($fp,"<GDFORM_VARIABLE NAME=$key END>\r\n");
	if ($key == "redirect") 
	{ 
		$landing_page = $val;
	}
}

fclose($fp);

if ($landing_page != "")
{
	header("Location: http://".$_SERVER["HTTP_HOST"]."/$landing_page");
} 
else 
{
	header("Location: http://".$_SERVER["HTTP_HOST"]."/");
}
?>

 

 

 

 

Just a basic email test gives me this error:  Warning: mail() [function.mail]: Failed to connect to mailserver at "relay-hosting.secureserver.net" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in D:\hosting\7746358\html\testmail.php on line 7

Mail Sent.

 

 

mailtest.php

 

<?php
$to = "someone@domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "noreply@mygodaddydomain.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
?>



Link to comment
https://forums.phpfreaks.com/topic/262878-godaddy-php-mail-problems/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.