使用PHPMailer发送电子邮件后重定向

时间:2017-08-09 14:37:09

标签: javascript php jquery email phpmailer

发送带PHPMailer的确认电子邮件后,我遇到了重定向问题。用户无法重定向到memberIndex.php

我试过了:

`$mail->Send();
header("Location:../memberIndex.php");
exit();`

同时关闭调试:

`$mail->SMTPDebug = 0;` 

ob_start/flush/clean等的所有组合

注意:当我将邮件正文($mail->Body)留空时,它会发送电子邮件并重定向。否则,它将保留在注册页面上。 在Body中,我有一些HTML标签和文本。可能是,身体会阻止重定向吗?

以下是我构建电子邮件的代码:

require '../../PHPMailer-master/PHPMailerAutoload.php';
$mail = new PHPMailer;
$mail->SMTPDebug = 0;
$mail->isSMTP();                                      // Set mailer to use SMTP
$mail->Host = 'host';  // Specify main and backup SMTP servers
$mail->SMTPAuth = true;                               // Enable SMTP authentication
$mail->Username = 'username';                 // SMTP username
$mail->Password = 'password';                           // SMTP password
$mail->SMTPSecure = 'ssl';                            // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465;                                    // TCP port to connect to

$mail->setFrom('info@test.com', 'test');
$mail->addAddress('test@test.com');     // Add a recipient


$mail->isHTML(true);                                  // Set email format to HTML
$mail->AddEmbeddedImage('../img/text_dark.png', 'cs');
$mail->Subject = 'Hi Customer!';

$body = 'test';

$mail->Body = $body;

$mail->Send();
header("Location:../memberIndex.php");
exit();
?>

1 个答案:

答案 0 :(得分:0)

在if块中至少包装/* global google */ import { default as React, Component } from 'react'; import raf from 'raf'; import canUseDOM from 'can-use-dom'; import { connect } from 'react-redux'; import { withGoogleMap, GoogleMap, Circle, InfoWindow, Marker } from 'react-google-maps'; import withScriptjs from 'react-google-maps/lib/async/withScriptjs'; const googleMapURL = 'https://maps.googleapis.com/maps/api/js?v=3.27&libraries=places,geometry&key=AIzaSyA7XEFRxE4Lm28tAh44M_568fCLOP_On3k'; const geolocation = canUseDOM && navigator.geolocation ? navigator.geolocation : { getCurrentPosition(success, failure) { failure("Your browser doesn't support geolocation."); }, }; const GeolocationExampleGoogleMap = withScriptjs( withGoogleMap(props => <GoogleMap defaultZoom={8} center={props.center}> {props.center && <InfoWindow position={props.center}> <div>User's Location</div> </InfoWindow>} {props.center && <Circle center={props.center} radius={props.radius} options={{ fillColor: 'red', fillOpacity: 0.2, strokeColor: 'red', strokeOpacity: 1, strokeWeight: 1, }} />} > {props.markers.map((marker, index) => { const onClick = () => props.onMarkerClick(marker); const onCloseClick = () => props.onCloseClick(marker); return ( <Marker key={index} position={marker.position} title={(index + 1).toString()} onClick={onClick} > {marker.showInfo && <InfoWindow onCloseClick={onCloseClick}> <div> <strong> <h2> {marker.content} </h2> </strong> <br /> <h3>Where we can add offer details!</h3> </div> </InfoWindow>} </Marker> ); })} </GoogleMap>, ), ); function generateInitialMarkers(items) { console.log('item', items); const markers = []; items.map((item, i) => { const newGeoArr = item.geolocation.split(','); item.position = { lat: newGeoArr[0], lng: newGeoArr[1] }; markers.push({ position: item.position, content: item.description, showInfo: false, }); }); console.log('markers: ', markers); return markers; } class OfferMap extends Component { constructor(props) { super(props); this.state = { center: null, content: null, radius: 100000, markers: generateInitialMarkers(this.props.browser.items), }; const isUnmounted = false; this.handleMarkerClick = this.handleMarkerClick.bind(this); this.handleCloseClick = this.handleCloseClick.bind(this); } handleMarkerClick(targetMarker) { this.setState({ markers: this.state.markers.map((marker) => { if (marker === targetMarker) { return { ...marker, showInfo: true, }; } return marker; }), }); } handleCloseClick(targetMarker) { this.setState({ markers: this.state.markers.map((marker) => { if (marker === targetMarker) { return { ...marker, showInfo: false, }; } return marker; }), }); } componentDidMount() { const tick = () => { if (this.isUnmounted) { return; } this.setState({ radius: Math.max(this.state.radius - 200, 0) }); if (this.state.radius > 100) { raf(tick); } }; geolocation.getCurrentPosition( (position) => { if (this.isUnmounted) { return; } this.setState({ center: { lat: position.coords.latitude, lng: position.coords.longitude, }, content: 'Location found using HTML5.', }); raf(tick); }, (reason) => { if (this.isUnmounted) { return; } this.setState({ center: { lat: 60, lng: 105, }, content: `Error: The Geolocation service failed (${reason}).`, }); }, ); } componentWillUnmount() { this.isUnmounted = true; } render() { return ( <GeolocationExampleGoogleMap googleMapURL={googleMapURL} loadingElement={<div style={{ height: '100%' }}>loading...</div>} containerElement={<div style={{ height: '100%' }} />} mapElement={<div style={{ height: '100%' }} />} center={this.state.center} content={this.state.content} radius={this.state.radius} onMarkerClick={this.handleMarkerClick} onCloseClick={this.handleCloseClick} markers={this.state.markers} /> ); } } function mapStateToProps({ browser }) { return { browser }; } export default connect(mapStateToProps)(OfferMap); (尝试...捕获会更好):

$mail->send()

得到一个线索什么可能出错。 另请查看PHP header manual.最重要的是在发送标头之前不要有任何输出。没有空格,没有错误,没有任何东西。