Jump to content

Recommended Posts

Hello All,

 

My name is Dragos and I try to use this script to send email:

 

<?php

//new function

 

$to = "office@gmail.com";

$nameto = "Who To";

$from = "office@mysite.com";

$namefrom = "Who From";

$subject = "Hello World Again!";

$message = "World, Hello!"

authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);

?>

 

 

<?php

/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

 

//Authenticate Send - 21st March 2005

//This will send an email using auth smtp and output a log array

//logArray - connection,

 

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)

{

//SMTP + SERVER DETAILS

/* * * * CONFIGURATION START * * * */

$smtpServer = "mail.mysite.com";

$port = "25";

$timeout = "30";

$username = "office@mysite.com";

$password = "password";

$localhost = "localhost";

$newLine = "\r\n";

/* * * * CONFIGURATION END * * * * */

 

//Connect to the host on the specified port

$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);

$smtpResponse = fgets($smtpConnect, 515);

if(empty($smtpConnect))

{

$output = "Failed to connect: $smtpResponse";

return $output;

}

else

{

$logArray['connection'] = "Connected: $smtpResponse";

}

 

//Request Auth Login

fputs($smtpConnect,"AUTH LOGIN" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['authrequest'] = "$smtpResponse";

 

//Send username

fputs($smtpConnect, base64_encode($username) . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['authusername'] = "$smtpResponse";

 

//Send password

fputs($smtpConnect, base64_encode($password) . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['authpassword'] = "$smtpResponse";

 

//Say Hello to SMTP

fputs($smtpConnect, "HELO $localhost" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['heloresponse'] = "$smtpResponse";

 

//Email From

fputs($smtpConnect, "MAIL FROM: $from" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['mailfromresponse'] = "$smtpResponse";

 

//Email To

fputs($smtpConnect, "RCPT TO: $to" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['mailtoresponse'] = "$smtpResponse";

 

//The Email

fputs($smtpConnect, "DATA" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['data1response'] = "$smtpResponse";

 

//Construct Headers

$headers = "MIME-Version: 1.0" . $newLine;

$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;

$headers .= "To: $nameto <$to>" . $newLine;

$headers .= "From: $namefrom <$from>" . $newLine;

 

fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");

$smtpResponse = fgets($smtpConnect, 515);

$logArray['data2response'] = "$smtpResponse";

 

// Say Bye to SMTP

fputs($smtpConnect,"QUIT" . $newLine);

$smtpResponse = fgets($smtpConnect, 515);

$logArray['quitresponse'] = "$smtpResponse";

}

?>

 

My problem is that cannot send emails to other email address, I can only send email to office@mysite.com.

Also this problem appeared when the company where I have my site hosting change the policy of email. After they change the policy my email was sent with abc02.abcdomains.com.

 

Please help me with other script or change this script.

 

Br,

Dragos

Link to comment
https://forums.phpfreaks.com/topic/219280-php-send-mail-problem/
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.