duankousong9637 2016-03-02 19:07
浏览 27

PHP(5.5),WebMatrix,SMTP和Windows

I am looking for some good information on setting up SMTP on windows 7 to be used with WebMatrix and PHP5.5

I have tried a few standard YouTube tutorials but they either lack the integration between SMTP and PHP or they outright ignore SMTP setup and configuration, all the others use Linux or MacOSx.

I don't really mind which solution to use as long as it can be easily ported to Unix, additionally to test the SMTP settings I found a "quick and dirty" script to use which I will put below.

I am quite new to SMTP and PHP so the only thing I know for certain is I should change the email in the code but cant see where I should tell it to use localhost as a server. Thanks for any help.

Test Script:

<?php
/*
DONT FORGET TO DELETE THIS SCRIPT WHEN FINISHED!
*/
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );

$from = 'webmaster@example.com';

/*
ini_set( 'SMTP', 'smtp.example.com' );
ini_set( 'SMTP_PORT', 25 );
ini_set( 'sendmail_from', $from );
*/

$server = array( 
    'HTTP_HOST', 'SERVER_NAME', 'SERVER_ADDR', 'SERVER_PORT',
    'SERVER_ADMIN', 'SERVER_SIGNATURE', 'SERVER_SOFTWARE', 
    'REMOTE_ADDR', 'DOCUMENT_ROOT', 'REQUEST_URI', 
    'SCRIPT_NAME', 'SCRIPT_FILENAME',
);

$to      = ( isset( $_GET['email'] ) ? $_GET['email'] : FALSE );
$subject = 'Mail Test Successful for ' . $_SERVER['HTTP_HOST'];
$message = '';

if ( ! $to )
{
    echo '<strong>Set $_GET[\'email\'].</strong>';
    exit;
};

foreach ( $server as $s )
{
    $message .= sprintf( '%s: %s', $s, $_SERVER[$s] ) . PHP_EOL;
};

$headers = 'From: ' . $from . PHP_EOL 
     . 'Reply-To: ' . $from . PHP_EOL 
     . 'X-Mailer: PHP/' . phpversion(); 

if ( isset( $_GET['send'] ) && $_GET['send'] === 'true' )
{                   
    $success = mail( $to, $subject, $message, $headers );
}
else
{
    echo '<strong>Set &quot;<a href="./?email=' . $to . '&send=true">'
     . './?email=' . $to . '&send=true</a>&quot; to send a test e-mail.</strong>';
};

if ( isset( $success ) )
{   
    echo 'E-mail sent to: ' . $to;
    echo '<br />';
    echo 'Successful mail?: <strong ' . ( $success ? 'style="color:green;">YES' : 'style="color:red;">NO' ) . '</strong>';
}
else
{
    echo '<br />';
    echo 'E-mail set as: '.$to;
};

echo '<hr />';  
echo '<style>   * { font-family: Helvetica, Arial, sans-serif;  } th { text-align: left; } td { padding: 3px 5px; } </style>';
echo '<table>'; 

foreach ( $server as $s )
{
    echo '<tr><th>$_SERVER[\'' . $s . '\']</th><td>' . $_SERVER[$s] . '</td></tr>';
};

echo '</table>';

if ( isset( $success ) )
{
    echo '<!--'; 
    var_dump( $success );       
    echo '-->';
};
?>
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求帮我调试一下freefem代码
    • ¥15 R语言Rstudio突然无法启动
    • ¥15 关于#matlab#的问题:提取2个图像的变量作为另外一个图像像元的移动量,计算新的位置创建新的图像并提取第二个图像的变量到新的图像
    • ¥15 改算法,照着压缩包里边,参考其他代码封装的格式 写到main函数里
    • ¥15 用windows做服务的同志有吗
    • ¥60 求一个简单的网页(标签-安全|关键词-上传)
    • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
    • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
    • ¥100 为什么这个恒流源电路不能恒流?
    • ¥15 有偿求跨组件数据流路径图